#include <bits/stdc++.h>
using namespace std;
const int DIM = 2007;
char s[DIM][DIM];
int jos[DIM][DIM];
long long calc(long long n) { return n * (n + 1) / 2; }
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> s[i][j];
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++) {
      jos[i][j] = 1;
      if (s[i][j] == s[i + 1][j]) jos[i][j] += jos[i + 1][j];
    }
  long long sol = 0LL;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int p = jos[i][j];
      if (i + 2 * p > n) continue;
      if (jos[i + p][j] != p || jos[i + 2 * p][j] < p) continue;
      int r = j - 1;
      while (r + 1 <= m && s[i][r + 1] == s[i][j] &&
             s[i + p][r + 1] == s[i + p][j] &&
             s[i + 2 * p][r + 1] == s[i + 2 * p][j] && jos[i][r + 1] == p &&
             jos[i + p][r + 1] == p && jos[i + 2 * p][r + 1] >= p)
        r++;
      sol += calc(r * 1LL - j + 1);
      j = r;
    }
  cout << sol;
}
