#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n, m, row[N][N], col[N][N], lst[30], ans, fac[N], ls;
char s[N][N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] + i;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  for (int j = 1; j <= m; j++) {
    ls = 0;
    for (int i = 1; i <= n; i++) {
      if (!ls || s[ls][j] != s[i][j])
        col[i][j] = ls = i;
      else
        col[i][j] = ls;
    }
  }
  for (int i = 1; i <= n; i++) {
    ls = 0;
    for (int j = 1; j <= m; j++) {
      if (!ls || s[i][ls] != s[i][j])
        row[i][j] = ls = j;
      else
        row[i][j] = ls;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int pos1 = col[i][j];
      if (pos1 <= 0) continue;
      int pos2 = col[pos1 - 1][j];
      if (pos2 <= 0) continue;
      int pos3 = col[pos2 - 1][j];
      if (pos3 <= 0) continue;
      if (s[i][j] != s[pos1 - 1][j] && s[pos1 - 1][j] != s[pos2 - 1][j] &&
          i - pos1 + 1 == pos1 - pos2 && pos1 - pos2 <= pos2 - pos3) {
        int tmp = -1e9;
        for (int k = i; k >= pos2 - (i - pos1 + 1); k--) {
          tmp = max(tmp, row[k][j]);
        }
        int pos4 = row[pos1][j], pos5 = row[pos2][j], pos6 = row[pos3][j];
        ans += (j - tmp + 1);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
