#include <bits/stdc++.h>
using namespace std;
char mp[2005][2005];
int dp[2005][2005];
int main() {
  int n, m;
  int sum = 0;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    getchar();
    for (int j = 1; j <= m; j++) {
      scanf("%c", &mp[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = 1;
      if (i >= 3 && j >= 2 && mp[i][j] == mp[i - 2][j] &&
          mp[i][j] == mp[i - 1][j - 1] && mp[i][j] == mp[i - 1][j + 1] &&
          mp[i][j] == mp[i - 1][j]) {
        dp[i][j] =
            min(dp[i - 2][j], min(dp[i - 1][j - 1], dp[i - 1][j + 1])) + 1;
      }
      sum += dp[i][j];
    }
  }
  cout << sum << endl;
  return 0;
}
