func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 10;   long long n, m, ans, h[N][N];   char ar[N][N];   bool get(long long i, long long j) {     long long x = h[i][j];     i -= x;     if (i < 0) return 0;     if (h[i][j] != x) return 0;     i -= x;     if (i < 0) return 0;     return h[i][j] >= x;   }   bool ok(long long row, long long l, long long r) {     long long x = h[row][l];     if (ar[row][l] != ar[row][r]) return 0;     row -= x;     if (ar[row][l] != ar[row][r]) return 0;     row -= x;     return ar[row][l] == ar[row][r];   }   long long choose2(long long x) { return (x * (x - 1)) / 2; }   long long solve(vector<bool> &vec, long long row) {     assert(vec.size() == m);     long long res = 0;     for (long long i = 0; i < vec.size(); i++) {       if (!vec[i]) continue;       long long r = i + 1;       while (r < vec.size() && vec[r] && h[row][i] == h[row][r] && ok(row, i, r))         r++;       res += choose2(r - i + 1);       i = r - 1;     }     return res;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) cin >> ar[i][j];     for (long long j = 0; j < m; j++) h[0][j] = 1;     for (long long i = 1; i < n; i++)       for (long long j = 0; j < m; j++) {         if (ar[i][j] == ar[i - 1][j])           h[i][j] = h[i - 1][j] + 1;         else           h[i][j] = 1;       }     for (long long i = 0; i < n; i++) {       vector<bool> vec;       for (long long j = 0; j < m; j++) vec.push_back(get(i, j));       ans += solve(vec, i);     }     cout << ans << endl;   }   