#include #include using namespace std; using namespace atcoder; using ll=long long; int main() { int h,w; cin>>h>>w; vector grid(h); for(int i=0;i>grid[i]; vector> seen(h,vector(w)); int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; for(int i=0;i bfs; bfs.push(i*w+j); set s; while(!bfs.empty()){ int x=bfs.front()/w,y=bfs.front()%w; s.insert(bfs.front()); bfs.pop(); for(int k=0;k<4;k++){ int nx=x+dx[k],ny=y+dy[k]; if(nx<0||nx>=h||ny<0||ny>=w||grid[x][y]!=grid[nx][ny]||seen[nx][ny])continue; seen[nx][ny]=true; bfs.push(nx*w+ny); } }if(s.size()>=4)for(int v:s)grid[v/w][v%w]='.'; } for(int i=0;i