#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, flag = 1;     char c = getchar();     while ((c >  9  || c <  0 ) && c !=  - ) c = getchar();     if (c ==  - ) flag = 0, c = getchar();     while (c <=  9  && c >=  0 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     return flag ? x : -x;   }   const int maxn = 2005;   int f[maxn][maxn];   char s[maxn][maxn];   int main() {     int n = read(), m = read();     for (int i = (1); i <= (int)(n); i++) scanf( %s , s[i] + 1);     for (int i = (1); i <= (int)(2); i++)       for (int j = (1); j <= (int)(m); j++) f[i][j] = 1;     for (int i = (3); i <= (int)(n); i++)       for (int j = (1); j <= (int)(m); j++) {         if (j == 1 || j == m) {           f[i][j] = 1;           continue;         }         if (s[i][j] != s[i - 1][j - 1] || s[i][j] != s[i - 1][j] ||             s[i][j] != s[i - 1][j + 1] || s[i][j] != s[i - 2][j]) {           f[i][j] = 1;           continue;         }         int x = 100000;         x = min(x, f[i - 1][j - 1]);         x = min(x, f[i - 1][j]);         x = min(x, f[i - 1][j + 1]);         x = min(x, f[i - 2][j]);         f[i][j] = x + 1;       }     long long ans = 0;     for (int i = (1); i <= (int)(n); i++)       for (int j = (1); j <= (int)(m); j++) ans += f[i][j];     cout << ans;     return 0;   }   