func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAXN = 2004;   const int INF = 0x3f3f3f3f;   char s[MAXN][MAXN];   int u[MAXN][MAXN], d[MAXN][MAXN];   int l[MAXN][MAXN], r[MAXN][MAXN];   int dp[MAXN][MAXN];   int n, m;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) scanf( %s , s[i]);     for (int i = 0; i < n; ++i) {       l[i][0] = 1;       r[i][m - 1] = 1;       dp[i][0] = dp[i][m - 1] = 1;       for (int j = 1; j < m; ++j) {         if (s[i][j - 1] == s[i][j])           l[i][j] = l[i][j - 1] + 1;         else           l[i][j] = 1;       }       for (int j = m - 2; j >= 0; --j) {         if (s[i][j + 1] == s[i][j])           r[i][j] = r[i][j + 1] + 1;         else           r[i][j] = 1;         dp[i][j] = min(l[i][j], r[i][j]);       }     }     for (int j = 0; j < m; ++j) {       u[0][j] = 1;       d[n - 1][j] = 1;       for (int i = 1; i < n; ++i) {         if (s[i - 1][j] == s[i][j])           u[i][j] = min(dp[i][j], u[i - 1][j] + 1);         else           u[i][j] = 1;       }       for (int i = n - 2; i >= 0; --i) {         if (s[i + 1][j] == s[i][j])           d[i][j] = min(dp[i][j], d[i + 1][j] + 1);         else           d[i][j] = 1;       }     }     int ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         ans += min(u[i][j], d[i][j]);       }     }     printf( %d n , ans);     return 0;   }   