#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
                 long long mod = (long long)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxn = 1100;
char string1[mxn];
char string2[mxn];
int xt1[mxn], xt2[mxn], xt3[mxn];
int bound[mxn];
int n, m;
void solution() {
  long long answer = 0;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", string2);
    long long composite = 0;
    for (int j = 0; j < m; j++) {
      if (string2[j] != string1[j]) {
        xt1[j] = xt2[j];
        xt2[j] = xt3[j];
        xt3[j] = 1;
      } else {
        xt3[j]++;
      }
      if (j > 0) {
        if (string2[j] == string2[j - 1])
          bound[j]++;
        else
          bound[j] = 0;
      }
      if (xt1[j] >= xt2[j] && xt2[j] == xt3[j]) {
        composite++;
        if (bound[j] < xt3[j] * 3) composite = 1;
      } else
        composite = 0;
      string1[j] = string2[j];
      answer += composite;
    }
  }
  cout << answer << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solution();
  return 0;
}
