#pragma region template /* template made by nouka28 last update 2024.6.30 */ //include #include using namespace std; //atcoder #include using namespace atcoder; using mint=atcoder::modint998244353; // using mint=atcoder::modint1000000007; // using mint=atcoder::modint; istream& operator>>(istream&is,mint &x){long long x_;is>>x_;x=x_;return is;} ostream& operator<<(ostream&os,mint &x){os<; using pl=pair; using pd=pair; templateusing V=vector; templateusing VV=V>; templateusing VVV=V>>; templateusing VVVV=V>>>; templateusing VVVVV=V>>>>; templateusing pqmax=priority_queue; templateusing pqmin=priority_queue,greater>; using u128=__uint128_t; using i128=__int128_t; //io INT128 i128 i128_parse(string &s){i128 ret=0;for(i32 i=0;i<(i32)s.length();i++)if('0'<=s[i]&&s[i]<='9')ret=10*ret+s[i]-'0';return ret;} u128 u128_parse(string &s){u128 ret=0;for(i32 i=0;i<(i32)s.length();i++)if('0'<=s[i]&&s[i]<='9')ret=10*ret+s[i]-'0';return ret;} istream &operator>>(istream &is,i128 &x){string s;is>>s;x=i128_parse(s);return is;} istream &operator>>(istream &is,u128 &x){string s;is>>s;x=u128_parse(s);return is;} ostream &operator<<(ostream &os,i128 x){ ostream::sentry s(os); if(s){u128 tmp=x<0?-x:x;char buffer[128];char *d=end(buffer); do{--d;*d="0123456789"[tmp%10];tmp/=10;}while(tmp!=0); if(x<0){--d;*d='-';} int len=end(buffer)-d; if (os.rdbuf()->sputn(d,len)!=len){os.setstate(ios_base::badbit);} } return os; } //const const i64 LINF=0x1fffffffffffffff; const i32 INF=0x3fffffff; const i64 MOD=998244353; const i64 MOD2=1000000007; const f80 PI=3.1415926535897932384626433832795028841971; const f80 DINF=numeric_limits::infinity(); const f80 EPS=1e-9; const i64 di[]={0,1,0,-1,1,-1,1,-1}; const i64 dj[]={1,0,-1,0,1,1,-1,-1}; //function #define overload4(_1,_2,_3,_4,name,...) name #define overload3(_1,_2,_3,name,...) name #define REP1(n) for(i64 i=0;i(a);) #define RREP4(i,a,b,c) for(i64 i=(a)+((b)-(a)-1)/(c)*(c)i>=a;i-=c) #define RREP(...) overload4(__VA_ARGS__,RREP4,RREP3,RREP2,RREP1)(__VA_ARGS__) #define SUM(...) accumulate(ALL(__VA_ARGS__),i64(0)) #define DSUM(...) accumulate(ALL(__VA_ARGS__),f80(0)) templatebool chmin(T &x,const T&y){if(x>y){x=y;return true;}return false;} templatebool chmax(T &x,const T&y){if(xbool lob(const V&arr,const T&v){return (i32)(lower_bound(ALL(arr),v)-arr.begin());} templatebool upb(const V&arr,const T&v){return (i32)(upper_bound(ALL(arr),v)-arr.begin());} templateconstexpr auto min(T a,T b,T c){return min(a,min(b,c));} templateconstexpr auto min(T... a){return min(initializer_list>{a...});} templateconstexpr auto max(T a,T b,T c){return max(a,max(b,c));} templateconstexpr auto max(T... a){return max(initializer_list>{a...});} //io struct SetUpIO{ SetUpIO(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout<>x;} void scan(u32&x){cin>>x;} void scan(u64 &x){cin>>x;} void scan(i32 &x){cin>>x;} void scan(i64 &x){cin>>x;} void scan(string &x){cin>>x;} void scan(mint &x){cin>>x;} templatevoid scan(pair &x){scan(x.first);scan(x.second);} templatevoid scan(V &x){for(T &ele:x){scan(ele);}} templatevoid scan(deque &x){for(T &ele:x){scan(ele);}} templatevoid scan(array &x){for(T &ele:x){scan(ele);}} templatevoid scan(T (&x)[size]){for(T &ele:x){scan(ele);}} void rd(){} templatevoid rd(Head &head,Tail &...tail){scan(head);rd(tail...);} #define CHR(...) char __VA_ARGS__;rd(__VA_ARGS__) #define U32(...) u32 __VA_ARGS__;rd(__VA_ARGS__) #define U64(...) u64 __VA_ARGS__;rd(__VA_ARGS__) #define I32(...) i32 __VA_ARGS__;rd(__VA_ARGS__) #define I64(...) i64 __VA_ARGS__;rd(__VA_ARGS__) #define STR(...) string __VA_ARGS__;rd(__VA_ARGS__) #define VEC(type,name,size) V name(size);rd(name); #define VVEC(type,name,size1,size2) VV name(size1,V(size2));rd(name) //out void print(){putchar(' ');} void print(bool x){printf("%d",x);} void print(u32 x){printf("%u",x);} void print(u64 x){printf("%llu",x);} void print(i32 x){printf("%d",x);} void print(i64 x){printf("%lld",x);} void print(char x){printf("%c",x);} void print(f64 x){printf("%.15f",x);} void print(f80 x){printf("%.15Lf",x);} void print(const string &x){for(auto&&i:x)print(i);} void print(mint x){printf("%d",x.val());} templatevoid print(const V&); templatevoid print(const pair&x){print(x.first);putchar(' ');print(x.second);} templatevoid print(complex&x){if(x.real()>=0)print('+');print(x.real());if(x.imag()>=0)print('+');print(x.imag());print('i');} templatevoid print(const V&x){if(x.empty())return;print(x[0]);for(auto i=x.begin();++i!=x.end();){putchar(' ');print(*i);}} templatevoid print(const deque&x){if(x.empty())return;print(x[0]);for(auto i=x.begin();++i!=x.end();){putchar(' ');print(*i);}} templatevoid print(const set&x){if(x.empty())return;print(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(' ');print(*i);}} templatevoid print(const unordered_set&x){if(x.empty())return;print(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(' ');print(*i);}} templatevoid print(const multiset&x){if(x.empty())return;print(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(' ');print(*i);}} templatevoid print(const unordered_multiset&x){if(x.empty())return;print(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(' ');print(*i);}} templatevoid print(map&x){if(x.empty())return;print(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(' ');print(*i);}} templatevoid print(unordered_map&x){if(x.empty())return;print(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(' ');print(*i);}} templatevoid print(const array&x){print(x[0]);for(auto i=x.begin();++i!=x.end();){putchar(' ');print(*i);}} templatevoid print(const T(&x)[size]){print(x[0]);for(auto i=x;++i!=end(x);){/*putchar(' ');*/print(*i);}} templatevoid print(const T&a){cout<int out(const T&t){print(t);putchar('\n');return 0;} templateint out(const Head&head,const Tail&...tail){print(head);putchar(' ');out(tail...);return 0;} #ifdef LOCAL void dbg(){putchar(' ');} void dbg(bool x){printf("%d",x);} void dbg(u32 x){printf("%u",x);} void dbg(u64 x){printf("%llu",x);} void dbg(i32 x){printf("%d",x);} void dbg(i64 x){printf("%lld",x);} void dbg(char x){printf("%c",x);} void dbg(f64 x){printf("%.15f",x);} void dbg(f80 x){printf("%.15Lf",x);} void dbg(const string &x){for(auto&&i:x)dbg(i);} void dbg(mint x){printf("%d",x.val());} templatevoid dbg(const V&); templatevoid dbg(const pair&x){putchar('(');dbg(x.first);putchar(',');dbg(x.second);putchar(')');} templatevoid dbg(complex&x){if(x.real()>=0)dbg('+');dbg(x.real());if(x.imag()>=0)dbg('+');dbg(x.imag());dbg('i');} templatevoid dbg(const V&x){putchar('[');if(!x.empty()){dbg(x[0]);for(auto i=x.begin();++i!=x.end();){putchar(',');dbg(*i);}}putchar(']');} templatevoid dbg(const deque&x){putchar('[');if(!x.empty()){dbg(x[0]);for(auto i=x.begin();++i!=x.end();){putchar(',');dbg(*i);}}putchar(']');} templatevoid dbg(const set&x){putchar('{');if(!x.empty()){dbg(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(',');dbg(*i);}}putchar('}');} templatevoid dbg(const unordered_set&x){putchar('{');if(!x.empty()){dbg(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(',');dbg(*i);}}putchar('}');} templatevoid dbg(const multiset&x){putchar('{');if(!x.empty()){dbg(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(',');dbg(*i);}}putchar('}');} templatevoid dbg(const unordered_multiset&x){putchar('{');if(!x.empty()){dbg(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(',');dbg(*i);}}putchar('}');} templatevoid dbg(map&x){putchar('{');if(!x.empty()){dbg(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(',');dbg(*i);}}putchar('}');} templatevoid dbg(unordered_map&x){putchar('{');if(!x.empty()){dbg(*x.begin());for(auto i=x.begin();++i!=x.end();){putchar(',');dbg(*i);}}putchar('}');} templatevoid dbg(const array&x){putchar('[');dbg(x[0]);for(auto i=x.begin();++i!=x.end();){putchar(',');dbg(*i);}putchar(']');} templatevoid dbg(const T(&x)[size]){/*putchar('[');*/dbg(x[0]);for(auto i=x;++i!=end(x);){/*putchar(' ')*/;dbg(*i);}/*putchar(']');*/} templatevoid dbg(const T&a){cout<int dbg2(const T&t){dbg(t);putchar('\n');return 0;} templateint dbg2(const Head&head,const Tail&...tail){dbg(head);putchar(' ');dbg2(tail...);return 0;} #define debug(...) {dbg((string)(#__VA_ARGS__));dbg(":");dbg2(__VA_ARGS__);} #else #define debug(...) void(0) #endif //random random_device rnd;mt19937 mt(rnd());const i64 MT_MAX=LINF; uniform_int_distribution RAND(0,MT_MAX); f64 randd(){return 1.0*RAND(mt)/MT_MAX;} //random value [a,b] i64 randint(i64 a,i64 b){return a+RAND(mt)%(b-a+1);} //funtion2 #define extrep(v,...) for(auto v:__MAKE_MAT__({__VA_ARGS__})) vector> __MAKE_MAT__(vector v){ if(v.empty())return vector>(1,vector()); i64 n=v.back();v.pop_back();vector> ret,tmp=__MAKE_MAT__(v); for(auto e:tmp)for(i64 i=0;i pair,vector> sortperm(vector v){ vector> sv; for(i32 i=0;i<(i32)v.size();i++){sv.push_back({v[i],i});} sort(sv.begin(),sv.end());vector rv;vector p; for(auto[x,idx]:sv){rv.push_back(x);p.push_back(idx);} return {rv,p}; } i64 pow(i64 a,i64 b){i64 x=1;while(b){if(b&1){x*=a;}a=a*a;b>>=1;}return x;} bool isupper(char x){return('A'<=x&&x<='Z');} bool islower(char x){return('a'<=x&&x<='z');} char upper(char &x){if(isupper(x)){return x;}return x-'a'+'A';} char lower(char &x){if(islower(x)){return x;}return x-'A'+'a';} string upper(string s){for(auto&e:s)e=upper(e);return s;} string lower(string s){for(auto&e:s)e=lower(e);return s;} bool isdigit(char x){return('0'<=x&&x<='9');} bool ingrid(int x,int y,int h,int w){return 0<=x&&x t(h,V(w)),t2(h,V(w)); auto dfs=[&](auto dfs,int i,int j,VV &t,bool f)->int { t[i][j]=1; int sz=1; for(int k=0;k<4;k++){ int ni=i+di[k],nj=j+dj[k]; if(ingrid(ni,nj,h,w)&&G[i][j]==G[ni][nj]&&!t[ni][nj])sz+=dfs(dfs,ni,nj,t,f); } if(f)G[i][j]='.'; return sz; }; REP(i,h)REP(j,w){ if(!t[i][j]){ if(dfs(dfs,i,j,t,0)>=4)dfs(dfs,i,j,t2,1); } } for(auto&&vec:G){for(auto&&c:vec)print(c);out();} }