#include <bits/stdc++.h>
using namespace std;
int n, m;
char xy[1005][1005];
int s1[1005][1005], s2[1005][1005];
int s3[1005][1005], s4[1005][1005];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", &xy[i][1]);
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      if (xy[i][j] == xy[i][j + 1]) s1[i][j] = s1[i][j + 1];
      s1[i][j]++;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = n; j >= 1; j--) {
      s3[j][i] = s1[j][i];
      if (xy[j][i] == xy[j + 1][i]) {
        s2[j][i] = s2[j + 1][i];
        s3[j][i] = min(s3[j][i], s3[j + 1][i]);
      }
      s2[j][i]++;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      s4[j][i] = s1[j][i];
      if (xy[j][i] == xy[j - 1][i]) s4[j][i] = min(s4[j][i], s4[j - 1][i]);
    }
  }
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int y1 = i;
      int y2 = y1 + s2[y1][j];
      int y3 = y2 + s2[y2][j];
      if (y1 != y2 && y2 != y3 && y1 != y3 && y2 - y1 == y3 - y2) {
        if (y3 - y2 <= s2[y3][j]) {
          int h = y3 - y2;
          res += min(s3[y1][j], min(s3[y2][j], s4[y3 + h - 1][j]));
        }
      }
    }
  }
  printf("%lld", res);
  return 0;
}
