#include <bits/stdc++.h>
using namespace std;
int n, m;
char x[1011][1011];
int z[1011][1011];
int ext[1011];
int y[1011][1011];
long long ans = 0;
bool cmp(int i, int j, int k, int h) {
  for (int l = 0; l < h; l++)
    if (x[i + l][j] != x[i + l][k]) return false;
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> x[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (z[i][j]) continue;
      int cnt = 1;
      for (int k = i + 1; k < n; k++) {
        if (x[k][j] == x[k - 1][j])
          cnt++;
        else
          break;
      }
      for (int k = i; k < i + cnt; k++) z[k][j] = cnt - (k - i);
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (z[i][j] == -1) continue;
      if (i + z[i][j] * 2 < n && z[i][j] == z[i + z[i][j]][j] &&
          z[i][j] <= z[i + z[i][j] + z[i][j]][j]) {
        int h = z[i][j] * 3;
        if (j > 0 && cmp(i, j, j - 1, h))
          y[i][j] = y[i][j - 1] + 1;
        else
          y[i][j] = 1;
        for (int k = 0; k < z[i][j]; k++) z[i + k][j] = -1;
        ans += y[i][j];
        ext[j] = i + z[i][j];
      } else
        ext[j] = i + 1;
    }
  cout << ans << endl;
  return 0;
}
