#include <bits/stdc++.h>
using namespace std;
long long read() {
  char c = getchar();
  long long flag = 1, ans = 0;
  while (c < '0' || c > '9') {
    if (c == '-') flag = -flag;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return ans * flag;
}
const long long INF = 1e16;
const long long MAXN = 2005;
long long l[MAXN][MAXN], r[MAXN][MAXN];
char c[MAXN][MAXN];
long long n, m, ans;
void dfs1(long long x, long long y) {
  l[x][y] = min(l[x - 1][y], l[x][y - 1]) + 1;
  if (c[x][y] != c[x - 1][y] || c[x][y] != c[x][y - 1]) l[x][y] = 0;
}
void dfs2(long long x, long long y) {
  r[x][y] = min(r[x + 1][y], r[x][y + 1]) + 1;
  if (c[x][y] != c[x + 1][y] || c[x][y] != c[x][y + 1]) r[x][y] = 0;
}
void dfs3(long long x, long long y) {
  r[x][y] = min(r[x + 1][y], r[x][y - 1]) + 1;
  if (c[x][y] != c[x + 1][y] || c[x][y] != c[x][y - 1]) r[x][y] = 0;
}
void dfs4(long long x, long long y) {
  r[x][y] = min(r[x - 1][y], r[x][y + 1]) + 1;
  if (c[x][y] != c[x - 1][y] || c[x][y] != c[x][y + 1]) r[x][y] = 0;
}
int main() {
  n = read(), m = read();
  for (long long i = 1; i <= n; ++i) scanf("%s", c[i] + 1);
  for (long long k = 2; k <= n + m; ++k)
    for (long long i = max(1ll, k - m); i <= n; ++i) {
      long long j = k - i;
      if (j <= 0) break;
      dfs1(i, j);
    }
  for (long long k = n + m; k >= 2; --k)
    for (long long i = min(k - 1ll, n); i >= 1; --i) {
      long long j = k - i;
      if (j > m) break;
      dfs2(i, j);
      l[i][j] = min(l[i][j], r[i][j]);
    }
  memset(r, 0, sizeof(r));
  for (long long i = n; i >= 1; --i)
    for (long long j = 1; j <= m; ++j) {
      dfs3(i, j);
      l[i][j] = min(l[i][j], r[i][j]);
    }
  memset(r, 0, sizeof(r));
  for (long long i = 1; i <= n; ++i)
    for (long long j = m; j >= 1; --j) {
      dfs4(i, j);
      l[i][j] = min(l[i][j], r[i][j]);
    }
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= m; ++j) ans += l[i][j] + 1;
  printf("%lld\n", ans);
  return 0;
}
