func_code_string: #include <bits/stdc++.h>   #pragma warning(disable : 4244 4267 4018 4996 4800)   using namespace std;   istream& in = std::cin;   ostream& out = std::cout;   int n, m, total;   int xstart = -1, ystart;   vector<vector<char>> p;   int res = -1;   bool ones(int x1, int y1, int x2, int y2) {     for (int i = x1; i <= x2; ++i)       for (int j = y1; j <= y2; ++j)         if (!p[i][j]) return false;     return true;   }   int count(int w, int h) {     int x = ::xstart, y = ::ystart;     int res = 0;     while (x < n && y < m && p[x][y]) {       if (x + h < n && p[x + h][y] && (y + w == m || !p[x][y + w])) {         if (ones(x, y, x, y + w - 1))           res += w;         else           return -1;         ++x;       } else if (y + w < m && p[x][y + w] && (x + h == n || !p[x + h][y])) {         if (ones(x, y, x + h - 1, y))           res += h;         else           return -1;         ++y;       } else         break;     }     if (x < n && y < m && p[x][y]) {       if (ones(x, y, x + h - 1, y + w - 1))         res += w * h;       else         return -1;     }     return res;   }   void trysolve() {     int w = 0, h = 0;     int i;     for (i = ystart; i < m && p[xstart][i]; ++i, ++w)       ;     int prev = -1;     for (i = xstart; i < n && p[i][ystart]; ++i) {       if (ystart + w < m && p[i][ystart + w] && prev == -1) {         prev = i;       }     }     h = prev == -1 ? 1 : i - prev;     if (count(w, h) == total && (res == -1 || w * h < res)) res = w * h;   }   template <class T>   vector<T> transpose(vector<T> const& t) {     vector<T> u(t[0].size(), T(t.size()));     for (unsigned i = 0; i < t.size(); ++i)       for (unsigned j = 0; j < t[i].size(); ++j) u[j][i] = t[i][j];     return u;   }   int main() {     std::ios_base::sync_with_stdio(false);     in >> n >> m;     string s;     p.resize(n, vector<char>(m));     for (auto& row : p) {       in >> s;       for (int i = 0; i < s.size(); ++i) row[i] = s[i] ==  X  ? 1 : 0;     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (p[i][j]) {           ++total;           if (xstart == -1) {             xstart = i;             ystart = j;           }         }       }     }     trysolve();     p = transpose(p);     swap(xstart, ystart);     swap(n, m);     trysolve();     out << res;     return 0;   }   