#include #include #include #include #include int dx[4]{ 0, 1, 0, -1 }, dy[4]{ 1, 0, -1, 0 }; int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int H, W; std::cin >> H >> W; std::vector S(H); for (auto& s : S) std::cin >> s; std::vector vis(H, std::vector(W)); auto in{[&](int x, int y) -> bool { return 0 <= x and x < H and 0 <= y and y < W; }}; auto dfs{[&](auto dfs, int x, int y, std::vector>& vs) -> void { vs.push_back(std::pair{ x, y }); vis[x][y] = true; for (int d{} ; d < 4 ; d++) { int nx{dx[d] + x}, ny{dy[d] + y}; if (!in(nx, ny)) continue; if (vis[nx][ny]) continue; if (S[x][y] != S[nx][ny]) continue; dfs(dfs, nx, ny, vs); } }}; for (int i{} ; i < H ; i++) for (int j{} ; j < W ; j++) if (!vis[i][j]) { std::vector> vs; dfs(dfs, i, j, vs); if (vs.size() >= 4u) { for (auto [x, y] : vs) S[x][y] = '.'; } } for (const auto& s : S) std::cout << s << '\n'; }