#include #include using namespace std; using namespace atcoder; using ll=long long; using ldub=long double; using lldub=__float128; using str=string; using mint=modint; template using tup2=tuple; template using tup3=tuple; template using tup4=tuple; template using tup5=tuple; template using tup6=tuple; template using tup7=tuple; template using vec=vector; template using vec2=vector>; template using vec3=vector>; template using vec4=vector>; template using vec5=vector>; template using vec6=vector>; template using que=queue; template using Pque=priority_queue; template using pque=priority_queue, greater>; struct Edge{ ll from,to,w=1,num=-1; }; using gvec=vector; using gvec2=vector; template bool chmax(T &a,T b){if(a bool chmin(T &a,T b){if(b grid_move(ll h,ll w,ll k){ if(k==0) return tup2(h+1,w); if(k==1) return tup2(h,w+1); if(k==2) return tup2(h-1,w); if(k==3) return tup2(h,w-1); } ll out(ll h,ll w,ll H,ll W){return h<0||H<=h||w<0||W<=w;} void solve(){ ll N; cin >> N; vec S(N); for(ll i=0;i> S[i]; vec2 A(N,vec(N)); for(ll i=0;i F(N,vec(N)); que> BFS; for(ll i=0;iC[ni][nj]) BFS.push(tup(ni,nj)); if(F[ni][nj]==1&&A[ni][nj]=C[i][j]) continue; F[i][j]=0; for(ll di=-1;di<=1;di++){ for(ll dj=-1;dj<=1;dj++){ ll ni=i+di,nj=j+dj; if(out(ni,nj,N,N)) continue; C[ni][nj]--; if(F[ni][nj]==0&&A[ni][nj]>C[ni][nj]) BFS.push(tup(ni,nj)); if(F[ni][nj]==1&&A[ni][nj]> T; while(T--) solve(); return 0; }