#include <bits/stdc++.h>
using namespace std;
char s[2000][2001];
long long dp[2000][2000][4];
int main() {
  int n, m;
  long long ans, temp;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      dp[i][j][0] = 1;
      dp[i][j][1] = 1;
      dp[i][j][2] = 1;
      dp[i][j][3] = 1;
    }
  for (int i = 1; i < n - 1; i++)
    for (int j = 1; j < m - 1; j++) {
      if (s[i][j] == s[i - 1][j] && s[i][j] == s[i][j - 1]) {
        temp = min(dp[i - 1][j][0], dp[i][j - 1][0]);
        dp[i][j][0] = temp + 1;
      }
    }
  for (int i = n - 2; i > 0; i--)
    for (int j = 1; j < m; j++) {
      if (s[i][j] == s[i + 1][j] && s[i][j] == s[i][j - 1]) {
        temp = min(dp[i + 1][j][1], dp[i][j - 1][1]);
        dp[i][j][1] = temp + 1;
      }
    }
  for (int i = 1; i < n - 1; i++)
    for (int j = m - 2; j > 0; j--) {
      if (s[i][j] == s[i - 1][j] && s[i][j] == s[i][j + 1]) {
        temp = min(dp[i - 1][j][2], dp[i][j + 1][2]);
        dp[i][j][2] = temp + 1;
      }
    }
  for (int i = n - 2; i > 0; i--)
    for (int j = m - 2; j > 0; j--) {
      if (s[i][j] == s[i + 1][j] && s[i][j] == s[i][j + 1]) {
        temp = min(dp[i + 1][j][3], dp[i][j + 1][3]);
        dp[i][j][3] = temp + 1;
      }
    }
  ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      ans += min(min(dp[i][j][0], dp[i][j][1]), min(dp[i][j][2], dp[i][j][3]));
  printf("%lld\n", ans);
  return 0;
}
