Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.

Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other.

Input

The first line of the input contains n (1 ≤ n ≤ 200 000) — the number of bishops.

Each of next n lines contains two space separated integers xi and yi (1 ≤ xi, yi ≤ 1000) — the number of row and the number of column where i-th bishop is positioned. It's guaranteed that no two bishops share the same position.

Output

Output one integer — the number of pairs of bishops which attack each other.

Example

Input
5
1 1
1 5
3 3
5 1
5 5
Output
6
Input
3
1 1
2 3
3 5
Output
0

Note

In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.

题意:在对角线上的相会相互攻击,求出能够相互攻击的相的对数?

题解:仔细观察能够发现,在同一对角线上的相满足x+y or x-y相等,这里需要注意的是x-y可能会出现负数,所以这里用x-y+3000来代替x-y

AC代码

#include<stdio.h>
#include<string.h> int main()
{
int n;
int x, y;
int attack[];
int sum;
while(~scanf("%d", &n))
{
sum = ;
memset(attack, , sizeof(attack));
for(int i = ; i < n; i++)
{
scanf("%d %d", &x, &y);
attack[x+y]++;
attack[x-y+]++;
}
for(int i = ; i < ; i++)
{
if(attack[i] > )
sum += attack[i]*(attack[i]-)/;
}
printf("%d\n", sum);
} return ;
}

Wet Shark and Bishops(思维)的更多相关文章

  1. B. Wet Shark and Bishops(思维)

    B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. Codeforces 612B. Wet Shark and Bishops 模拟

    B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  3. Codeforces Round #341 Div.2 B. Wet Shark and Bishops

    题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...

  4. 【CodeForces 621B】Wet Shark and Bishops

    题 题意 1000*1000的格子里,给你n≤200 000个点的坐标,求有多少对在一个对角线上. 分析 如果求每个点有几个共对角线的点,会超时. 考虑到对角线总共就主对角线1999条+副对角线199 ...

  5. codeforce 621B Wet Shark and Bishops

    对角线 x1+y1=x2+y2 或者x1-y1=x2-y2 #include<iostream> #include<string> #include<algorithm& ...

  6. Chocolate&&木块拼接&&Cards&& Wet Shark and Bishops

    B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  7. CodeForces 621B Wet Shark and Bishops

    记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...

  8. Codeforces--621B--Wet Shark and Bishops(数学)

     B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input ...

  9. Wet Shark and Flowers(思维)

    C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. -3dB的理解

    -3dB到底是什么?集成运放-3dB带宽又是什么? 以无源高通电路为例,介绍-3dB的意义. 输出与输入只比: Au=Uo/Ui=R/(R+1/j*2*PI*f*C)=1/(1+1/j*2*PI*f* ...

  2. SpringBoot外部配置

    Spring Boot的配置文件 Spring Boot使用一个全局的配置文件application.properties或者application.yml(yaml语言的配置文件),放置在src/m ...

  3. java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest

    转自:https://blog.csdn.net/iteye_17476/article/details/82651580 java.lang.ClassCastException: org.apac ...

  4. mahout in Action研读(1)-给用户推荐图书

    1.mahout in Action2.2第一个例子   Running a first recommender engine   数据: 第一个数字是用户ID 第二个是书的ID,第三个是用户对书的评 ...

  5. Python之整数,浮点数和布尔类型

    整数和浮点数有那个四则运算: 两种类型的数可以直接进行加减,当整数和浮点数进行加减的时候,结果会自动的变为浮点数,其中除法运算是“/”来表示的, 而余数的算术符号是“%”来表示的.如果是为了求除完后的 ...

  6. JavaScript中数值和对象

    一.创建对象并将其初始化  a.使用new创建对象和方法 <<!DOCTYPE html> <html> <head> <mete http-equiv ...

  7. Maven学习笔记2-maven命令

    help:active-profiles列出当前构建中活动的Profile(项目的,用户的,全局的). help:effective-pom显示当前构建的实际POM,包含活动的Profile. hel ...

  8. c#日期与字符串间的转换(转)

    1.日期转字符串(转载) 在编程中经常要用到将日期变量转换为字符串的情况,而且不同的时候希望转换成不同格式的字符串 下面是一些常用的转换及转换结果: (查看格式说明) 以日期为例: 2009-09-0 ...

  9. Codeforces 56D Changing a String (DP)

    题意:你可以对字符串s进行3种操作: 1,在pos位置插入字符ch. 2,删除pos位置的字符. 3,替换pos位置的字符为ch. 问最少需要多少次操作可以把字符s变成字符s1? 思路: 设dp[i] ...

  10. 51NOD 1616 最小集合

    传送门 分析 不难发现集合中的数一定是集合内其它一堆数的$gcd$ 于是我们枚举$i$,统计原来集合中有几个数是$i$的倍数,设这个值为$f(i)$ 之后对于每个$i$如果不存在$f(x*i) = f ...