#include <bits/stdc++.h>
using namespace std;
const int N = 1050;
char s[N][N];
int ri[N][N], d[N][N], a[N], f[10][N][N];
int main() {
  int n, m;
  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 = m; j >= 1; j--) {
      ri[i][j] = 1;
      if (s[i][j + 1] == s[i][j]) ri[i][j] = 1 + ri[i][j + 1];
    }
  for (int j = 1; j <= m; j++)
    for (int i = n; i >= 1; i--) {
      d[i][j] = 1;
      if (s[i][j] == s[i + 1][j]) d[i][j] = 1 + d[i + 1][j];
    }
  for (int j = 1; j <= m; j++)
    for (int i = 1; i <= n; i++) f[0][i][j] = ri[i][j];
  for (int k = 1; k < 10; k++)
    for (int j = 1; j <= m; j++)
      for (int i = 1; i <= n - (1 << (k - 1)); i++)
        f[k][i][j] = min(f[k - 1][i][j], f[k - 1][i + (1 << (k - 1))][j]);
  a[1] = 0;
  for (int i = 0; i < 10; i++)
    for (int k = 1 << i; k < (1 << (i + 1)); k++) a[k] = i;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x1 = i, x2 = i + d[i][j], x3 = x2 + d[x2][j];
      if (d[x2][j] != d[i][j] || d[i][j] > d[x3][j]) continue;
      int l = d[i][j], t = n;
      int u = a[3 * l];
      ans += min(f[u][i][j], f[u][i + 3 * l - (1 << u)][j]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
