#include #define int ll using namespace std; #define rep(i,n) for(int i=0;i=0;i--) #define rng(i,c,n) for(int i=c;i #define _4ab8goq ios::sync_with_stdio(0),cin.tie(0); typedef long long ll; typedef vector vi; typedef pair pii; void print(){cout<<'\n';} template void print(const h&v,const t&...u){cout<>h>>w>>n>>d; vec(pii) a(n); rep(i,n){ cin>>a[i].fi>>a[i].se; } rep(i,n){ a[i].fi-=1,a[i].se-=1; } map mp; rep(i,n){ mp[a[i]]=i; } auto ok=[&](int i,int j){ return min(i,j)>=0 and id) continue; int nx=x+di,ny=y+dj; if(ok(nx,ny) and mp.find(pii(nx,ny))!=mp.end()){ uf.merge(i,mp[{nx,ny}]); } } } } int cnt=0; rep(i,n){ if(uf.parent(i)==i){ if(uf.size(i)>1){ cnt+=1; } } } int mi=1e9,ma=0; rep(i,h){ rep(j,w){ int x=i,y=j; set st; rng(di,-d,d+1){ rng(dj,-d,d+1){ if(abs(di)+abs(dj)>d) continue; int nx=x+di,ny=y+dj; if(ok(nx,ny) and mp.find(pii(nx,ny))!=mp.end()){ st.insert(uf.parent(mp[{nx,ny}])); } } } int now=cnt,e=0; for(auto v:st){ if(uf.size(v)>1){ e+=1; } } // if(i==3 and j==2) print(sz(st),e); if(!e){ now+=(sz(st)>0); }else{ now-=(e-1); } mi=min(mi,now); ma=max(ma,now); } } cout<