#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, ans, a[N][N];
char c[N][N];
int get(int x, int y, int add) {
  int res = 1;
  while (c[x][y] == c[x + add][y]) {
    x += add;
    res++;
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> c[i][j];
  for (int i = 2; i < n; i++) {
    for (int j = 1; j <= m; j++) {
      if (c[i][j] != c[i - 1][j]) {
        a[i][j] = get(i, j, 1);
        if (get(i - 1, j, -1) < a[i][j] || get(i + a[i][j], j, 1) < a[i][j] ||
            i + a[i][j] == n + 1)
          a[i][j] = 0;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1, cnt = 0; j <= m; j++) {
      if (a[i][j])
        if (a[i][j] == a[i][j - 1] && c[i][j] == c[i][j - 1] &&
            c[i - 1][j] == c[i - 1][j - 1] &&
            c[i + a[i][j]][j] == c[i + a[i][j]][j - 1])
          ans += (++cnt);
        else
          ans += (cnt = 1);
      else
        cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
