# AT2160 へんなコンパス / Manhattan Compass

### 传送门

$|x1-x2|=dis\\ |y1-y2|<=dis$

$|y1-y2|=dis\\ |x1-x2|<=dis$

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char ch;bool ok;
for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1e5+10;bool vis[maxn];
int n,a,b,len,sum[maxn],pre[maxn*10],nxt[maxn*10],h[maxn],cnt;
long long ans;
struct oo{int x,y,id;}s[maxn];
pre[++cnt]=y,nxt[cnt]=h[x],h[x]=cnt;
pre[++cnt]=x,nxt[cnt]=h[y],h[y]=cnt;
}
bool cmp(oo a,oo b){return a.x==b.x?(a.y<b.y):a.x<b.x;}
void solve(int dis){
sort(s+1,s+n+1,cmp);
int l=1,r=0,pos=1;
for(rg int i=1;i<=n;i++){
while(l<n&&(s[l].x<s[i].x-len||(s[l].x==s[i].x-len&&s[l].y<s[i].y-dis)))l++;
while(r<n&&(s[r+1].x<s[i].x-len||(s[r+1].x==s[i].x-len&&s[r+1].y<=s[i].y+dis)))r++;
sum[s[i].id]+=r-l+1;pos=max(pos,l);
pos--;
}
}
void dfs(int x){
vis[x]=1;ans+=sum[x];
for(rg int i=h[x];i;i=nxt[i])
if(!vis[pre[i]])dfs(pre[i]);
}
int main(){