func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   void print(T a) {     for (auto x : a) cout << x <<    ;     cout <<   n ;   }   void solve() {     int n, m;     cin >> n >> m;     char a[n][m];     short down[n][m], up[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         down[i][j] = 0;         up[i][j] = 0;       }     }     short l[m], r[m];     for (int j = 0; j < m; j++) up[0][j] = 1;     int ans = 0;     for (int i = 1; i < n; i++) {       for (int j = 0; j < m; j++) {         if (j == 0 || (a[i][j - 1] != a[i][j]))           l[j] = j;         else           l[j] = l[j - 1];       }       for (int j = m - 1; j >= 0; j--) {         if (j == m - 1 || (a[i][j + 1] != a[i][j]))           r[j] = j;         else           r[j] = r[j + 1];       }       for (int j = 0; j < m; j++) {         int x = 1;         if (a[i - 1][j] == a[i][j]) x = up[i - 1][j] + 1;         x = min(x, j - l[j] + 1);         x = min(x, r[j] - j + 1);         up[i][j] = x;       }     }     for (int j = 0; j < m; j++) down[n - 1][j] = 1;     for (int i = n - 2; i >= 0; i--) {       for (int j = 0; j < m; j++) {         if (j == 0 || (a[i][j - 1] != a[i][j]))           l[j] = j;         else           l[j] = l[j - 1];       }       for (int j = m - 1; j >= 0; j--) {         if (j == m - 1 || (a[i][j + 1] != a[i][j]))           r[j] = j;         else           r[j] = r[j + 1];       }       for (int j = 0; j < m; j++) {         int x = 1;         if (a[i + 1][j] == a[i][j]) x = down[i + 1][j] + 1;         x = min(x, j - l[j] + 1);         x = min(x, r[j] - j + 1);         down[i][j] = x;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         short res = min(up[i][j], down[i][j]);         ans += res;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 0; i < t; i++) {       solve();     }     return 0;   }   