#include <bits/stdc++.h>
using namespace std;
vector<string> a(1000);
vector<vector<int64_t>> c(1000, vector<int64_t>(1000, 0));
bool check(int64_t i, int64_t j, int64_t s) {
  int64_t cg = c[i + 3 * s - 1][j] - c[i][j];
  if (cg != 2) return 0;
  if (c[i + 2 * s][j] - c[i + 2 * s - 1][j] != 1) return 0;
  if (c[i + s][j] - c[i + s - 1][j] != 1) return 0;
  return 1;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int64_t n, m;
  cin >> n >> m;
  for (int64_t i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int64_t j = 0; j < m; ++j) {
    for (int64_t i = 1; i < n; ++i) {
      c[i][j] = ((a[i][j] != a[i - 1][j]) ? 1 : 0) + c[i - 1][j];
    }
  }
  vector<vector<int64_t>> d(n, vector<int64_t>(m, 0));
  int64_t ans = 0;
  for (int64_t s = 1; 3 * s <= n; ++s) {
    for (int64_t i = 0; i + 3 * s - 1 < n; ++i) {
      int64_t j = 0;
      while (j < m) {
        if (!check(i, j, s)) {
          ++j;
          continue;
        }
        int64_t cnt = 0;
        char p = a[i][j], q = a[i + s][j], r = a[i + 2 * s][j];
        if (p == q || q == r) {
          ++j;
          continue;
        }
        d[i][j]++;
        while (j < m) {
          if (!check(i, j, s)) break;
          if (a[i][j] != p || a[i + s][j] != q || a[i + 2 * s][j] != r) break;
          cnt++;
          ++j;
        }
        ans += cnt * (cnt + 1) / 2;
      }
    }
  }
  cout << ans << endl;
}
