#include using namespace std; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector A(h); cin >> A; vector B(h, vector(w)); vector> vec; for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ if(B[y][x]) continue; vec.clear(); B[y][x] = true; vec.emplace_back(y, x); for(int i = 0; i < vec.size(); i++){ auto [cy, cx] = vec[i]; for(int i = 0; i < 4; i++){ int ny = cy + (i == 0) - (i == 1); int nx = cx + (i == 2) - (i == 3); if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue; if(A[y][x] != A[ny][nx] || B[ny][nx]) continue; B[ny][nx] = true; vec.emplace_back(ny, nx); } } if(vec.size() >= 4) for(auto [y, x] : vec) A[y][x] = '.'; } cout << A[y] << '\n'; } }