#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
template <typename T>
void read(T &x) {
  bool neg = false;
  unsigned char c = getchar();
  for (; (c ^ 48) > 9; c = getchar())
    if (c == '-') neg = true;
  for (x = 0; (c ^ 48) < 10; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
  if (neg) x = -x;
}
int n, m, l[N][N], r[N][N], u[N][N], d[N][N], s[N][N];
long long ans;
char a[N][N + 1];
int main() {
  read(n);
  read(m);
  for (int i = 0, i_end = n; i < i_end; ++i) scanf("%s", a[i]);
  for (int i = 0, i_end = n; i < i_end; ++i)
    for (int j = 0, j_end = m; j < j_end; ++j) l[i][j] = 1;
  for (int i = 0, i_end = n; i < i_end; ++i)
    for (int j = 1, j_end = m; j < j_end; ++j)
      if (a[i][j] == a[i][j - 1]) l[i][j] += l[i][j - 1];
  for (int i = 0, i_end = n; i < i_end; ++i)
    for (int j = 0, j_end = m; j < j_end; ++j) r[i][j] = 1;
  for (int i = 0, i_end = n; i < i_end; ++i)
    for (int j = m - 2; ~j; --j)
      if (a[i][j] == a[i][j + 1]) r[i][j] += r[i][j + 1];
  for (int j = 0, j_end = m; j < j_end; ++j) u[0][j] = 1;
  for (int i = 1, i_end = n; i < i_end; ++i)
    for (int j = 0, j_end = m; j < j_end; ++j) {
      int line = l[i][j] < r[i][j] ? l[i][j] : r[i][j];
      int now = u[i - 1][j] + 1;
      if (now > line) now = line;
      if (a[i][j] != a[i - 1][j]) now = 1;
      u[i][j] = now;
    }
  for (int j = 0, j_end = m; j < j_end; ++j) d[n - 1][j] = 1;
  for (int i = n - 2; ~i; --i)
    for (int j = 0, j_end = m; j < j_end; ++j) {
      int line = l[i][j] < r[i][j] ? l[i][j] : r[i][j];
      int now = d[i + 1][j] + 1;
      if (now > line) now = line;
      if (a[i][j] != a[i + 1][j]) now = 1;
      d[i][j] = now;
    }
  for (int i = 0, i_end = n; i < i_end; ++i)
    for (int j = 0, j_end = m; j < j_end; ++j)
      s[i][j] = u[i][j] < d[i][j] ? u[i][j] : d[i][j];
  for (int i = 0, i_end = n; i < i_end; ++i)
    for (int j = 0, j_end = m; j < j_end; ++j) ans += s[i][j];
  printf("%lld\n", ans);
  return 0;
}
