#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int lt[n][m];
  int dn[n][m];
  string flag[n];
  for (int i = 0; i < n; i++) cin >> flag[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j == 0 || (flag[i][j] != flag[i][j - 1]))
        lt[i][j] = 1;
      else
        lt[i][j] = 1 + lt[i][j - 1];
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = n - 1; ~i; i--) {
      if (i == n - 1 || (flag[i][j] != flag[i + 1][j]))
        dn[i][j] = 1;
      else
        dn[i][j] = 1 + dn[i + 1][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int h = dn[i][j];
      int p = i + h;
      if (dn[p][j] != h) continue;
      p += h;
      if (dn[p][j] < h || p >= n) continue;
      int cur = lt[p][j];
      p += h;
      for (int k = i; k < p; k++) {
        cur = min(cur, lt[k][j]);
      }
      ans += cur;
    }
  }
  cout << ans << endl;
}
