#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
char C[maxn][maxn];
int f[maxn][maxn];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", C[i] + 1);
  int ans = 0;
  for (int len = 1; 3 * len <= n; len++)
    for (int i = 1; i + 3 * len - 1 <= n; i++) {
      char la, lb, lc;
      int sum = 0, cnt = 0;
      for (int j = 1; j <= m; j++) {
        if (f[i][j]) {
          cnt = 0;
          continue;
        }
        char a = C[i][j], b = C[i + len][j], c = C[i + 2 * len][j];
        if (a == b || b == c) {
          la = a, lb = b, lc = c;
          cnt = 0;
          continue;
        }
        int flag = 0;
        for (int k = 1; k < len; k++) {
          if (C[i + k][j] != a || C[i + len + k][j] != b ||
              C[i + 2 * len + k][j] != c) {
            flag = 1;
            la = a, lb = b, lc = c;
            f[i][j] = 1;
            cnt = 0;
            break;
          }
        }
        if (flag) continue;
        if (j != 1 && (la != a || lb != b || lc != c))
          cnt = 1;
        else
          cnt++;
        f[i][j] = 1;
        sum += cnt;
        la = a, lb = b, lc = c;
      }
      ans += sum;
    }
  cout << ans << endl;
  return 0;
}
