#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
int n, m;
char s[MAXN][MAXN];
int l[MAXN][MAXN], r[MAXN][MAXN], u[MAXN][MAXN], d[MAXN][MAXN];
int L[MAXN][MAXN], R[MAXN][MAXN], U[MAXN][MAXN], D[MAXN][MAXN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      u[i][j] = s[i][j] == s[i - 1][j] ? u[i - 1][j] + 1 : 1;
      l[i][j] = s[i][j] == s[i][j - 1] ? l[i][j - 1] + 1 : 1;
    }
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--) {
      d[i][j] = s[i][j] == s[i + 1][j] ? d[i + 1][j] + 1 : 1;
      r[i][j] = s[i][j] == s[i][j + 1] ? r[i][j + 1] + 1 : 1;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      U[i][j] = s[i][j] == s[i - 1][j]
                    ? min(U[i - 1][j] + 1, min(l[i][j], r[i][j]))
                    : 1;
      L[i][j] = s[i][j] == s[i][j - 1]
                    ? min(L[i][j - 1] + 1, min(u[i][j], d[i][j]))
                    : 1;
    }
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--) {
      D[i][j] = s[i][j] == s[i + 1][j]
                    ? min(D[i + 1][j] + 1, min(l[i][j], r[i][j]))
                    : 1;
      R[i][j] = s[i][j] == s[i][j + 1]
                    ? min(R[i][j + 1] + 1, min(u[i][j], d[i][j]))
                    : 1;
    }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      ans += min(min(L[i][j], R[i][j]), min(U[i][j], D[i][j]));
  printf("%d\n", ans);
  return 0;
}
