func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 10;   int n, m, cnt, counter, b[maxn * maxn], par[maxn][maxn];   char a[maxn][maxn];   vector<pair<int, int> > adj[maxn][maxn];   bool mark[maxn][maxn];   void dfs(int x, int y) {     mark[x][y] = true;     par[x][y] = cnt;     counter++;     for (int i = 0; i < adj[x][y].size(); i++) {       int x1 = adj[x][y][i].first;       int y1 = adj[x][y][i].second;       if (!mark[x1][y1]) dfs(x1, y1);     }   }   int f(int x, int y) {     int A[4] = {0};     if (x != 0 && a[x - 1][y] ==  . ) A[0] = par[x - 1][y];     if (x != n - 1 && a[x + 1][y] ==  . ) A[1] = par[x + 1][y];     if (y != 0 && a[x][y - 1] ==  . ) A[2] = par[x][y - 1];     if (y != m - 1 && a[x][y + 1] ==  . ) A[3] = par[x][y + 1];     for (int i = 0; i < 4; i++)       for (int j = i + 1; j < 4; j++)         if (A[i] == A[j]) A[j] = 0;     int ans = 0;     if (x != 0) ans += b[A[0]];     if (x != n - 1) ans += b[A[1]];     if (y != 0) ans += b[A[2]];     if (y != m - 1) ans += b[A[3]];     ans++;     ans %= 10;     return ans;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (a[i][j] ==  . ) {           if (i != 0)             if (a[i - 1][j] ==  . ) adj[i][j].push_back(pair<int, int>(i - 1, j));           if (i != n - 1)             if (a[i + 1][j] ==  . ) adj[i][j].push_back(pair<int, int>(i + 1, j));           if (j != 0)             if (a[i][j - 1] ==  . ) adj[i][j].push_back(pair<int, int>(i, j - 1));           if (j != m - 1)             if (a[i][j + 1] ==  . ) adj[i][j].push_back(pair<int, int>(i, j + 1));         }       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (!mark[i][j]) {           counter = 0;           cnt++;           dfs(i, j);           b[cnt] = counter;         }       }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  . )           printf( . );         else {           printf( %d , f(i, j));         }       }       printf(  n );     }   }   