#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int n, m, l[2005][2005], r[2005][2005], u[2005][2005], d[2005][2005];
char mp[2005][2005];
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) {
    scanf("%s", (mp[i] + 1));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == mp[i - 1][j])
        u[i][j] = u[i - 1][j] + 1;
      else
        u[i][j] = 1;
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == mp[i + 1][j])
        d[i][j] = d[i + 1][j] + 1;
      else
        d[i][j] = 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == mp[i][j - 1])
        l[i][j] = min(l[i][j - 1] + 1, min(u[i][j], d[i][j]));
      else
        l[i][j] = 1;
    }
    for (int j = m; j >= 1; j--) {
      if (mp[i][j] == mp[i][j + 1])
        r[i][j] = min(r[i][j + 1] + 1, min(u[i][j], d[i][j]));
      else
        r[i][j] = 1;
    }
    for (int j = 1; j <= m; j++) ans += min(l[i][j], r[i][j]);
  }
  printf("%d\n", ans);
}
