#include <bits/stdc++.h>
using namespace std;
int V, n, m, ans, r[1005], ls[4000005], rs[4000005], f[4000005], a[1005][1005],
    b[1005][1005];
char s[1005][1005];
void build(int k, int l, int r, int x) {
  if (l == r) {
    f[k] = a[l][x];
    return;
  }
  build(ls[k] = ++V, l, (l + r >> 1), x);
  build(rs[k] = ++V, (l + r >> 1) + 1, r, x);
  f[k] = min(f[ls[k]], f[rs[k]]);
}
int query(int k, int l, int r, int x, int y) {
  if ((x > r) || (l > y)) return 0x3f3f3f3f;
  if ((x <= l) && (r <= y)) return f[k];
  return min(query(ls[k], l, (l + r >> 1), x, y),
             query(rs[k], (l + r >> 1) + 1, r, x, y));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  for (int i = 0; i < n; i++) {
    a[i][0] = 1;
    for (int j = 1; j < m; j++)
      if (s[i][j] == s[i][j - 1])
        a[i][j] = a[i][j - 1] + 1;
      else
        a[i][j] = 1;
  }
  for (int i = 0; i < m; i++) build(r[i] = ++V, 0, n - 1, i);
  for (int i = 0; i < m; i++) {
    b[0][i] = 1;
    for (int j = 1; j < n; j++)
      if (s[j][i] == s[j - 1][i])
        b[j][i] = b[j - 1][i] + 1;
      else
        b[j][i] = 1;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int ch = b[i][j];
      if (i - 3 * ch + 1 < 0) continue;
      if (b[i - ch][j] != ch) continue;
      if (b[i - 2 * ch][j] < ch) continue;
      int ku = query(r[j], 0, n - 1, i - 3 * ch + 1, i);
      ans += ku;
    }
  }
  printf("%lld", ans);
}
