#include <bits/stdc++.h>
using namespace std;
long long n, m, ans, sum[1010][1010], cnt[1010][1010], lt;
char c[1010][1010];
int ck(int x, int y) {
  int l = sum[x][y];
  x -= l;
  if (sum[x][y] != l) {
    return 0;
  }
  x -= l;
  if (sum[x][y] >= l) {
    return l;
  } else {
    return 0;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == 1 || c[i][j] != c[i - 1][j]) {
        sum[i][j] = 1;
      } else {
        sum[i][j] = sum[i - 1][j] + 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int now = ck(i, j);
      if (!now) {
        lt = 0;
        continue;
      }
      cnt[i][j] = 1;
      if (lt == now && c[i][j] == c[i][j - 1] &&
          c[i - now][j] == c[i - now][j - 1] &&
          c[i - 2 * now][j] == c[i - 2 * now][j - 1]) {
        cnt[i][j] += cnt[i][j - 1];
      }
      ans += cnt[i][j];
      lt = now;
    }
  }
  cout << ans << endl;
  return 0;
}
