#include <bits/stdc++.h>
using namespace std;
const int maxn = 1111;
char A[maxn][maxn];
int down[maxn][maxn];
long long n, m;
inline int calc(int r, int c) {
  int mid = down[r][c] + 1;
  if (mid == n) return -1;
  int mid2 = down[mid][c] + 1;
  if (mid2 == n) return -1;
  int a = mid - r, b = mid2 - mid, d = down[mid2][c] - mid2 + 1;
  if (a != b || a > d) return -1;
  return a;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) scanf("%s", &A[i]);
  for (int j = 0; j < m; ++j) {
    int last = n - 1;
    for (int i = n - 1; i >= 0; --i) {
      if (A[i][j] != A[last][j]) last = i;
      down[i][j] = last;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int len = calc(i, j);
      if (len == -1) continue;
      long long k = j + 1;
      while (k < m && calc(i, k) == len && A[i][j] == A[i][k] &&
             A[i + len][j] == A[i + len][k] &&
             A[i + len * 2][j] == A[i + len * 2][k])
        ++k;
      --k;
      long long L = k - j + 1;
      ans += L * (L + 1) / 2;
      j = k;
    }
  }
  cout << ans << endl;
  return 0;
}
