#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int out = 0, fh = 1;
  char jp = getchar();
  while ((jp > '9' || jp < '0') && jp != '-') jp = getchar();
  if (jp == '-') fh = -1, jp = getchar();
  while (jp >= '0' && jp <= '9') out = out * 10 + jp - '0', jp = getchar();
  return out * fh;
}
const int MAXN = 1e3 + 10;
int n, m;
int col[MAXN][MAXN];
char buf[MAXN];
int D[MAXN][MAXN];
int k[MAXN][MAXN];
const int inf = 1e9;
struct seg {
  int val[MAXN << 2];
  void bd(int y, int o, int l, int r) {
    if (l == r) {
      val[o] = k[l][y];
      return;
    }
    int mid = (l + r) >> 1;
    bd(y, o << 1, l, mid);
    bd(y, o << 1 | 1, mid + 1, r);
    val[o] = min(val[o << 1], val[o << 1 | 1]);
  }
  int query(int o, int l, int r, int L, int R) {
    assert(val[o]);
    if (L <= l && r <= R) return val[o];
    int mid = (l + r) >> 1;
    int s = inf;
    if (L <= mid) s = min(s, query(o << 1, l, mid, L, R));
    if (R > mid) s = min(s, query(o << 1 | 1, mid + 1, r, L, R));
    assert(s >= 1 && s <= m);
    return s;
  }
} T[MAXN];
long long calc(int x, int y) {
  int p1 = x;
  int p2 = D[p1][y] + 1;
  if (p2 > n) return 0;
  int p3 = D[p2][y] + 1;
  if (p3 > n) return 0;
  int len = p2 - p1;
  if (p3 != p2 + len) return 0;
  if (p3 + len - 1 > n) return 0;
  if (D[p3][y] < p3 + len - 1) return 0;
  return T[y].query(1, 1, n, p1, p3 + len - 1);
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; ++i) {
    scanf("%s", buf + 1);
    for (int j = 1; j <= m; ++j) col[i][j] = buf[j] - 'a' + 1;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = m; j >= 1; --j)
      if (col[i][j] != col[i][j + 1])
        k[i][j] = 1;
      else
        k[i][j] = k[i][j + 1] + 1;
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = n; i >= 1; --i)
      if (col[i][j] != col[i + 1][j])
        D[i][j] = i;
      else
        D[i][j] = D[i + 1][j];
  }
  for (int j = 1; j <= m; ++j) T[j].bd(j, 1, 1, n);
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) ans += calc(i, j);
  cout << ans << endl;
  return 0;
}
