#include <bits/stdc++.h>
using namespace std;
int n, m, dp[1005][1005];
long long ans;
string g[1005];
int main() {
  int i, j, cnt, pa, pb, pc, pd, a, b, c, d;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> g[i];
    g[i] = " " + g[i];
  }
  for (i = n; i >= 1; i--) {
    for (j = 1; j <= m; j++) {
      dp[i][j] = g[i][j] == g[i + 1][j] ? dp[i + 1][j] + 1 : 1;
    }
  }
  for (i = 1; i <= n; i++) {
    cnt = 0;
    pa = -1, pb = -1, pc = -1, pd = -1;
    for (j = 1; j <= m; j++) {
      a = i, b = a + dp[a][j], c = b + dp[b][j], d = c + dp[c][j];
      if (c <= n && b - a == c - b && b - a <= d - c) {
        if (pc <= n && pa == a && pb == b && pc == c && pb - pa <= pd - pc &&
            g[a][j] == g[a][j - 1] && g[b][j] == g[b][j - 1] &&
            g[c][j] == g[c][j - 1]) {
          cnt++;
        } else {
          ans += (cnt * (cnt + 1)) >> 1;
          cnt = 1;
        }
      }
      pa = a, pb = b, pc = c, pd = d;
    }
    ans += (cnt * (cnt + 1)) / 2;
  }
  cout << ans << endl;
  return 0;
}
