func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 200010;   int n, m;   char s[2020][2020];   int dp[2020][2020], a[2020][2020][2], dp1[2020][2020];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %s , s[i]);       for (int j = 0; j < m; ++j) {         if (j == 0) {           a[i][j][0] = 0;         } else {           if (s[i][j] == s[i][j - 1]) {             a[i][j][0] = a[i][j - 1][0] + 1;           } else {             a[i][j][0] = 0;           }         }       }       for (int j = m - 1; j >= 0; --j) {         if (j == m - 1) {           a[i][j][1] = 0;         } else {           if (s[i][j] == s[i][j + 1]) {             a[i][j][1] = a[i][j + 1][1] + 1;           } else {             a[i][j][1] = 0;           }         }       }       if (i == 0) {         for (int j = 0; j < m; ++j) {           dp[i][j] = 0;         }       } else {         for (int j = 0; j < m; ++j) {           if (s[i - 1][j] == s[i][j])             dp[i][j] = min(dp[i - 1][j] + 1, min(a[i][j][0], a[i][j][1]));           else             dp[i][j] = 0;         }       }     }     for (int i = n - 1; i >= 0; --i) {       for (int j = 0; j < m; ++j) {         if (j == 0) {           a[i][j][0] = 0;         } else {           if (s[i][j] == s[i][j - 1]) {             a[i][j][0] = a[i][j - 1][0] + 1;           } else {             a[i][j][0] = 0;           }         }       }       for (int j = m - 1; j >= 0; --j) {         if (j == m - 1) {           a[i][j][1] = 0;         } else {           if (s[i][j] == s[i][j + 1]) {             a[i][j][1] = a[i][j + 1][1] + 1;           } else {             a[i][j][1] = 0;           }         }       }       if (i == n - 1) {         for (int j = 0; j < m; ++j) {           dp1[i][j] = 0;         }       } else {         for (int j = 0; j < m; ++j) {           if (s[i][j] == s[i + 1][j])             dp1[i][j] = min(dp1[i + 1][j] + 1, min(a[i][j][0], a[i][j][1]));           else             dp1[i][j] = 0;         }       }     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         dp[i][j] = min(dp[i][j], dp1[i][j]);         ans += dp[i][j] + 1;       }     }     cout << ans << endl;   }   