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. Azure VM的加速网络

    Azure的VM在经过几代发展后已经有多种硬件类型.目前Azure China的多种机型都配置了FPGA卡,可以实现网络加速.本文将介绍Azure的加速网络相关的内容. 一. 加速网络的硬件准备 下图 ...

  2. POJ2236(并查集入门)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 22977   Accepted: 961 ...

  3. svn Can't revert without reverting children 解决方案

    EMZ3.0 qrh$ svn commit -m ""svn: E155010: Commit failed (details follow):svn: E155010: '/U ...

  4. JavaScript,Dom,jQuery

    JavaScript JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript 语言的规则编写相应代码,浏览器可以解释出相应的处理. 注 ...

  5. java继承。顾不了

    总结:为什么结果显示所有数据都重复输出了呢? package com.sa; //java里的几个难以理解的概念.字节码文件.class文件.源文件 //.class文件指的是.编译后产生的字节码文件 ...

  6. stdin和STDIN_FILENO的区别

    STDIN_FILENO与stdin的区别: STDIN_FILENO: 1).数据类型:int 2).层次:系统级的API,是一个文件句柄,定义在<unistd.h>中. 3).相应的函 ...

  7. 11-16网页基础--HTML

    网页制作部分主要讲解三大部分: 1.HTML    超文本标记语言( 全称:Hyper Text  Markup Language) 专门编辑静态网页 2.CSS      网页美化:是HTML控制的 ...

  8. CentOS6.5安装完没有网络的解决办法

    昨天下了个CentOS 6.5 Minimal 版,在VMware 10下安装好了之后,发现上不了网,PING外网也PING不通. 在网上搜了一下,发现Linux安装好了之后,网卡默认是没有启动的,下 ...

  9. DAY17-认证系统

    COOKIE 与 SESSION 概念 cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此cookie就是在这样一个场景下诞生. cookie ...

  10. Mac系统下MySql下载MySQL5.7及详细安装流程

    一.在浏览器当中输入以下地址 https://dev.mysql.com/downloads/mysql/    二.进入以下界面:直接点击下面位置 ,选择跳过登录 点过这后直接下载. 三.下载完成后 ...