#include #define syosu(x) fixed< P; typedef pair pdd; typedef pair pll; typedef vector vi; typedef vector vvi; typedef vector vd; typedef vector vvd; typedef vector vl; typedef vector vvl; typedef vector vs; typedef vector

vp; typedef vector vvp; typedef vector vpll; typedef pair pip; typedef vector vip; const int inf=1<<29; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-18; const ll mod=1e9+7; const int dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,-1,0,1,-1,1,-1,1}; int w,h; vvi a,b; bool dfs(int x,int y,int c){ b[x][y]=c; bool B=1; for(int i=0;i<8;i++){ int X=x+dx[i],Y=y+dy[i]; if(X>=0&&X=0&&Y>w>>h; a=vvi(h,vi(w)); for(int i=0;i>a[i][j]; bool B=0; for(int i=1;i<=1000;i++){ b=a; for(int j=1;j