#include using namespace std; #define st first #define nd second #define pb push_back #define mp make_pair using ll = long long; using db = double; using ldb = long double; using pii = pair; using pll = pair; const int nax = 105; char a[nax][nax]; int n, m; bool vis[nax][nax]; vector dir = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)}; bool ok(int r, int c){ return (r >= 1 && r <= n && c >= 1 && c <= m); } vector bfs(int r, int c){ vector Q; Q.pb(mp(r, c)); vis[r][c] = true; int wsk = 0; while(wsk < Q.size()){ pii cur = Q[wsk++]; for(pii go : dir){ pii to = mp(cur.st + go.st, cur.nd + go.nd); if(ok(to.st, to.nd) && !vis[to.st][to.nd] && a[to.st][to.nd] == a[r][c]){ Q.pb(to); vis[to.st][to.nd] = true; } } } return Q; } string res = ""; string reku(int r, int c){ auto all = bfs(r, c); vector adjDif; for(pii cur : all){ for(pii go : dir){ pii to = mp(cur.st + go.st, cur.nd + go.nd); if(ok(to.st, to.nd) && a[to.st][to.nd] != a[r][c]){ adjDif.pb(to); } } } int cnt = 0; string res = ""; sort(adjDif.begin(), adjDif.end()); for(pii adj : adjDif){ if(!vis[adj.st][adj.nd]){ string gg = reku(adj.st, adj.nd); res += gg; cnt += 1; } } if(cnt != 0){ char app = 'a' + cnt - 1; res = app + res; } return res; } char wynik[3111][3111]; void solve(){ cin >> n >> m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin >> a[i][j]; } } string res = reku(1, 1); reverse(res.begin(), res.end()); int rows = 3000; int cols = 3000; for(int i=1;i<=rows;i++){ for(int j=1;j<=cols;j++){ wynik[i][j] = '.'; } } cout << rows << " " << cols << "\n"; vector znaki = {'#', '.'}; for(int i=0;i 0){ wynik[botRow - 1][j] = znaki[idRamka ^ 1]; ile -= 1; } else wynik[botRow - 1][j] = znaki[idRamka]; } } char rst = znaki[res.size() % 2]; int sz = res.size(); for(int i=sz+1;i<=rows-sz * 3;i++){ for(int j=sz+1;j<=cols-sz;j++){ wynik[i][j] = rst; } } for(int i=1;i<=rows;i++){ for(int j=1;j<=cols;j++) cout << wynik[i][j]; cout << "\n"; } } int main() { solve(); return 0; }