#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int H, W, x, y; cin >> H >> W; vector S(H), T; for (int i=0; i> S[i]; T = S; vector> v; int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; auto check=[&](int x, int y){ return 0<=x && x(W)); auto dfs=[&](auto self, int x, int y)->void{ int nx, ny; used[x][y] = 1; v.push_back({x, y}); for (int k=0; k<4; k++){ nx = x+dx[k]; ny = y+dy[k]; if (!check(nx, ny) || used[nx][ny]) continue; if (S[x][y] != S[nx][ny]) continue; self(self, nx, ny); } }; for (int i=0; i=4){ for (auto [x, y] : v){ T[x][y] = '.'; } } v.clear(); } } for (int i=0; i