func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T, typename V>   ostream &operator<<(ostream &out, const pair<T, V> x) {     out <<  {  << x.first <<   :   << x.second <<  } ;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const set<T> x) {     for (auto &it : x) {       out << it <<    ;     }     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const multiset<T> x) {     for (auto &it : x) {       out << it <<    ;     }     return out;   }   template <typename T, typename V>   ostream &operator<<(ostream &out, const map<T, V> x) {     for (auto &it : x) {       out <<  [  << it.first <<  ]            <<   =   << it.second <<   n ;     }     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> x) {     for (int i = 0; i < x.size() - 1; ++i) {       out << x[i] <<    ;     }     out << x.back();     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<vector<T> > x) {     for (int i = 0; i < x.size() - 1; ++i) {       out <<  [  << i <<  ]            <<   = {  << x[i] <<  } n ;     }     out <<  [  << x.size() - 1 <<  ]          <<   = {  << x.back() <<  } n ;     return out;   }   const int N = 1e6 + 5;   const int MOD = 1e9 + 7;   const int INF = 1e9;   vector<vector<char> > a, ans;   vector<vector<int> > cnt, dst;   int n, m;   long long get(long long x1, long long y1, long long x2, long long y2) {     --x1, --y1;     if (x1 < 0 || y1 < 0) return 0;     return cnt[x2][y2] - cnt[x1][y2] - cnt[x2][y1] + cnt[x1][y1];   }   queue<pair<long long, long long> > qu;   void bfs(long long x) {     while (!qu.empty()) {       pair<long long, long long> cr = qu.front();       qu.pop();       for (int i = -1; i <= 1; ++i) {         for (int j = -1; j <= 1; ++j) {           if (dst[cr.first + i][cr.second + j] == 0) {             if (cr.first + i <= 0 || cr.first + i > n || cr.second + j <= 0 ||                 cr.second + j > m)               continue;             dst[cr.first + i][cr.second + j] = dst[cr.first][cr.second] + 1;             qu.push({cr.first + i, cr.second + j});           }         }       }     }   }   bool solve(long long x) {     while (!qu.empty()) qu.pop();     long long sz = 2 * x + 1;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         ans[i][j] =  . ;         dst[i][j] = 0;         long long c = get(i - sz + 1, j - sz + 1, i, j);         if (c == sz * sz) ans[i - x][j - x] =  X ;         if (i >= x && j >= x && ans[i - x][j - x] ==  X ) {           qu.push({i - x, j - x});           dst[i - x][j - x] = 1;         }       }     }     if (qu.empty()) return false;     bfs(x);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (a[i][j] ==  X  && dst[i][j] > x + 1) return false;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     a.resize(n + 2, vector<char>(m + 2));     ans.resize(n + 2, vector<char>(m + 2));     cnt.resize(n + 2, vector<int>(m + 2));     dst.resize(n + 2, vector<int>(m + 2));     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cin >> a[i][j];         cnt[i][j] =             cnt[i][j - 1] + cnt[i - 1][j] - cnt[i - 1][j - 1] + (a[i][j] ==  X );       }     }     int l = 0, r = INF;     while (r - l > 1) {       int mid = (l + r) >> 1;       if (solve(mid)) {         l = mid;       } else {         r = mid;       }     }     if (solve(r))       cout << r;     else if (solve(l))       cout << l;     cout <<   n ;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cout << ans[i][j];       }       cout <<   n ;     }     return 0;   }   