#include <bits/stdc++.h>
using namespace std;
long long int a[1005][1005];
long long int d[1005][1005], r[1005][1005];
long long int tree[4 * 1005][1005];
long long int power(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
void build(long long int low, long long int high, long long int ind,
           long long int pos) {
  if (low == high) {
    tree[pos][ind] = r[low][ind];
    return;
  }
  long long int mid = (low + high) / 2;
  build(low, mid, ind, 2 * pos + 1);
  build(mid + 1, high, ind, 2 * pos + 2);
  tree[pos][ind] = min(tree[2 * pos + 1][ind], tree[2 * pos + 2][ind]);
}
long long int query(long long int low, long long int high, long long int ind,
                    long long int pos, long long int qlow,
                    long long int qhigh) {
  if (qlow <= low && high <= qhigh) return tree[pos][ind];
  if (qlow > high || qhigh < low) return LLONG_MAX;
  long long int mid = (low + high) / 2;
  long long int u = query(low, mid, ind, 2 * pos + 1, qlow, qhigh);
  long long int v = query(mid + 1, high, ind, 2 * pos + 2, qlow, qhigh);
  return (min(u, v));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      char c;
      cin >> c;
      a[i][j] = c - 'a';
    }
  }
  for (long long int j = 0; j < m; j++) d[0][j] = 1;
  for (long long int i = 1; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (a[i][j] == a[i - 1][j])
        d[i][j] = d[i - 1][j] + 1;
      else
        d[i][j] = 1;
    }
  }
  for (long long int i = 0; i < n; i++) r[i][0] = 1;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 1; j < m; j++) {
      if (a[i][j] == a[i][j - 1])
        r[i][j] = r[i][j - 1] + 1;
      else
        r[i][j] = 1;
    }
  }
  for (long long int i = 0; i < m; i++) build(0, n - 1, i, 0);
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      long long int c = d[i][j];
      if (i >= 2 * c && d[i - c][j] == c && d[i - c - c][j] >= c)
        ans += query(0, n - 1, j, 0, i + 1 - 3 * c, i);
    }
  }
  cout << ans << endl;
}
