#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int H,W,N,D; cin >> H >> W >> N >> D; vector> star(H,vector(W)),already = star; while(N--){ int x,y; cin >> x >> y; x--; y--; star.at(x).at(y) = true; } vector> dec(H,vector(W)),inc = dec; int answer = 0; stack> st; for(int i=0; i> Q; Q.push({i,k}); while(Q.size()){ auto[x,y] = Q.front(); Q.pop(); st.push({x,y}); for(int i=0; i<=5; i++) for(int k=-5; k<=5; k++){ if(abs(i)+abs(k) > D) continue; int nx = x+i,ny = y+k; if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue; if(already.at(nx).at(ny) || !star.at(nx).at(ny)) continue; already.at(nx).at(ny) = true; Q.push({nx,ny}); } } if(st.size() >= 2){ answer++; set> added; while(st.size()){ auto[x,y] = st.top(); st.pop(); for(int i=-5; i<=5; i++) for(int k=-5; k<=5; k++){ if(abs(i)+abs(k) > D) continue; int nx = x+i,ny = y+k; if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue; if(star.at(nx).at(ny)) continue; if(added.count({nx,ny})) continue; dec.at(nx).at(ny)++; added.insert({nx,ny}); } } } else{ while(st.size()){ auto[x,y] = st.top(); st.pop(); for(int i=-5; i<=5; i++) for(int k=-5; k<=5; k++){ if(abs(i)+abs(k) > D) continue; int nx = x+i,ny = y+k; if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue; if(star.at(nx).at(ny)) continue; inc.at(nx).at(ny)++; } } } } int maxa = answer,mina = answer; for(int i=0; i