#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int U = 1 << 10;
int dat[U * 2];
int query(int l, int r) {
  l += U;
  r += U - 1;
  int res = 1e9;
  while (l <= r) {
    if ((l & 1) == 1) res = min(res, dat[l++]);
    if ((r & 1) == 0) res = min(res, dat[r--]);
    l >>= 1;
    r >>= 1;
  }
  return res;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < (H); i++) cin >> S[i];
  vector<vector<int>> succ(H, vector<int>(W, H));
  for (int j = 0; j < (W); j++) {
    for (int i = (int)(H - 1) - 1; i >= 0; i--) {
      if (S[i + 1][j] == S[i][j]) {
        succ[i][j] = succ[i + 1][j];
      } else {
        succ[i][j] = i + 1;
      }
    }
  }
  vector<vector<int>> cnt(H, vector<int>(W, 1));
  for (int i = 0; i < (H); i++) {
    for (int j = (int)(W - 1) - 1; j >= 0; j--) {
      if (S[i][j + 1] == S[i][j]) {
        cnt[i][j] += cnt[i][j + 1];
      }
    }
  }
  ll ans = 0;
  for (int j = 0; j < (W); j++) {
    for (int i = 0; i < (H); i++) {
      dat[i + U] = cnt[i][j];
    }
    for (int i = U - 1; i >= 1; i--) {
      dat[i] = min(dat[i * 2], dat[i * 2 + 1]);
    }
    for (int i1 = 0; i1 < (H); i1++) {
      if (succ[i1][j] == H) continue;
      int i2 = succ[i1][j];
      if (succ[i2][j] == H) continue;
      int i3 = succ[i2][j];
      int i4 = succ[i3][j];
      int x = i2 - i1;
      int y = i3 - i2;
      int z = i4 - i3;
      if (x != y || x > z) continue;
      ans += query(i1, i3 + x);
    }
  }
  cout << ans << '\n';
}
