思路:维护主对角线和副对角线上的点的数量,然后加起来就好了
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
#define maxn 1010
#define LL long long
int cas=1,T;
LL dpl[maxn][maxn];
LL dpr[maxn][maxn];
int main()
{
int n;
scanf("%d",&n);
for (int i = 1;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
dpl[x][y]=1;
dpr[x][y]=1;
}
LL ans = 0;
for (int i = 1;i<=1000;i++)
for (int j = 1;j<=1000;j++)
{
if (dpl[i][j])
{
ans+=dpl[i-1][j-1];
ans+=dpr[i-1][j+1];
}
dpl[i][j]+=dpl[i-1][j-1];
dpr[i][j]+=dpr[i-1][j+1];
}
printf("%lld\n",ans);
//freopen("in","r",stdin);
//scanf("%d",&T);
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}