#include <bits/stdc++.h>
using namespace std;
const int MN = 1100;
int n, m, c[MN][MN];
char s[MN][MN];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> s[i] + 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      c[i][j] = (s[i][j] == s[i - 1][j]) ? c[i - 1][j] + 1 : 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == s[i + 1][j]) continue;
      int h = c[i][j];
      if (i - h < 1 or i + h > n) continue;
      if (c[i][j] > c[i - h][j] or c[i][j] != c[i + h][j]) continue;
      int col = j;
      while (s[i][j] == s[i][col + 1] and c[i][j] == c[i][col + 1] and
             s[i - h][j] == s[i - h][col + 1] and
             c[i][j] <= c[i - h][col + 1] and
             s[i + 1][j] == s[i + h][col + 1] and
             c[i + h][j] == c[i + h][col + 1]) {
        col++;
      }
      int w = col - j + 1;
      ans += w * (w + 1) / 2;
      j = col;
    }
  }
  cout << ans << endl;
  return 0;
}
