#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>h>>w; for(int i=0;i>st[i][j]; memset(dp,0,sizeof(dp)); int ans=0; auto in=[&](int y,int x){return 0<=y&&y; queue

q; q.emplace(y,x); dp[y][x]=1; while(!q.empty()){ tie(y,x)=q.front();q.pop(); for(int k=0;k<4;k++){ int ny=y+dy[k],nx=x+dx[k]; if(!in(ny,nx)||!st[ny][nx]) continue; if(dp[ny][nx]) continue; q.emplace(ny,nx); dp[ny][nx]=1; } } ans++; }; for(int i=0;i