#include <bits/stdc++.h> using namespace std; const int N=2e3+5; bitset<N> mat[N]; bool vis[N][N]; int cnt,tot; int n,m; array<int, 2> stk[N*N]; int tp; int dir[5] = {1, 0, -1, 0, 1}; void clear(){ while(tp) { auto [x, y] = stk[tp--]; if(mat[x][y] == 0) { vis[x][y] = false; cnt--; ...