func_code_string: #include <bits/stdc++.h>   using namespace std;   char s[1005][1005];   int sum[1005][1005];   int mn = 1000000007, area = 0;   int X, Y, n, m;   int extend(int x, int y, int dx, int dy) {     int mx = 0;     if (x + dx <= n && y + dy - 1 <= m &&         sum[x + dx][y + dy - 1] - sum[x + dx][y - 1] - sum[x][y + dy - 1] +                 sum[x][y - 1] ==             dx * dy)       mx = dy + extend(x + 1, y, dx, dy);     else if (y + dy <= m && x + dx - 1 <= n &&              sum[x + dx - 1][y + dy] - sum[x + dx - 1][y] - sum[x - 1][y + dy] +                      sum[x - 1][y] ==                  dx * dy)       mx = dx + extend(x, y + 1, dx, dy);     return mx;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> (s[i] + 1);     int x, y;     for (x = 1; x <= n; x++) {       for (y = 1; y <= m; y++)         if (s[x][y] ==  X ) break;       if (y < m + 1) break;     }     X = x, Y = y;     int extX = 0, extY = 0;     for (int i = x; i <= n; i++)       if (s[i][y] ==  X ) extX++;     for (int i = y; i <= m; i++)       if (s[x][i] ==  X ) extY++;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] +                      (s[i][j] ==  X )),         area += (s[i][j] ==  X );       }     for (int dx = 1; dx <= extX; dx++) {       if (dx * extY > mn) break;       if (sum[x + dx - 1][y + extY - 1] - sum[x + dx - 1][y - 1] -               sum[x - 1][y + extY - 1] + sum[x - 1][y - 1] ==           dx * extY) {         int dArea = dx * extY + extend(x, y, dx, extY);         if (dArea == area && dx * extY < mn) mn = dx * extY;       }     }     for (int dy = 1; dy <= extY; dy++) {       if (dy * extX > mn) break;       if (sum[x + extX - 1][y + dy - 1] - sum[x + extX - 1][y - 1] -               sum[x - 1][y + dy - 1] + sum[x - 1][y - 1] ==           extX * dy) {         int dArea = dy * extX + extend(x, y, extX, dy);         if (dArea == area && extX * dy < mn) mn = extX * dy;       }     }     if (mn == 1000000007)       cout <<  -1  << endl;     else       cout << mn << endl;   }   