#include using namespace std; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main(){ int H, W; cin >> H >> W; vector G(H); for (int i = 0; i < H; i++){ cin >> G[i]; } vector> vis(H, vector(W)); for (int i = 0; i < H; i++){ for (int j = 0; j < W; j++){ if (vis[i][j]){ continue; } queue> q; q.push(make_pair(i, j)); vector> A; A.push_back(make_pair(i, j)); vis[i][j] = true; while (!q.empty()){ auto [x, y] = q.front(); q.pop(); for (int k = 0; k < 4; k++){ int px = x + dx[k], py = y + dy[k]; if (0 <= px and px < H and 0 <= py and py < W and !vis[px][py]){ if (G[px][py] == G[i][j]){ q.push(make_pair(px, py)); A.push_back(make_pair(px, py)); vis[px][py] = true; } } } } if (A.size() >= 4){ for (auto [x, y] : A){ G[x][y] = '.'; } } } } for (int i = 0; i < H; i++){ cout << G[i] << endl; } }