思路:求对角线相同的对数,显然可以由第一个样例得知,同一个对角线的要么x+y相同,要么x-y相同,那么随便记录一下,每一个的贡献是cnt[i]*(cnt[i]-1)/2
#include<bits\stdc++.h>
using namespace std;
int cnt1[10005];
int cnt2[10005];
int main()
{
int n;
int ans = 0;
cin >>n;
for(int i = 1;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
cnt1[x+y]++;
cnt2[x-y+1000]++;
}
for(int i = 0;i<=2005;i++)
{
ans+=cnt1[i]*(cnt1[i]-1)/2;
ans+=cnt2[i]*(cnt2[i]-1)/2;
}
cout << ans << endl;
}