#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int infi = 1147483600;
const long long infl = 1e17;
const char ENDL = '\n';
int n, m;
int MAP[1005][1005];
long long calc(int i, int j, long long ans, vector<vector<bool> > &checked) {
  int len = 0;
  int x0 = i - 1, x1 = i, x2 = i;
  while (x2 < n && MAP[x1][j] == MAP[x2][j]) {
    checked[x2][j] = true;
    x2++;
  }
  len = x2 - x1;
  if (x2 >= n) {
    return ans;
  }
  for (long long ii = (long long)x2; ii < (long long)x2 + len; ii++) {
    if (ii >= n || MAP[ii][j] != MAP[x2][j]) return ans;
  }
  x0 = x1 - len;
  for (long long ii = (long long)x0; ii < (long long)x0 + len; ii++) {
    if (ii < 0 || MAP[ii][j] != MAP[x0][j]) return ans;
  }
  long long res = 1;
  for (long long jj = (long long)j + 1; jj < (long long)m; jj++) {
    bool flag = true;
    for (long long ii = (long long)x0; ii < (long long)x2 + len; ii++) {
      if (MAP[ii][j] != MAP[ii][jj]) {
        flag = false;
        break;
      }
    }
    if (!(flag)) {
      break;
    }
    res = jj - j + 1;
    for (long long ii = (long long)x1; ii < (long long)x2; ii++)
      checked[ii][jj] = true;
  }
  return ans + res * (res + 1) / 2;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (long long i = 0; i < (long long)n; i++) {
    string s;
    cin >> s;
    for (long long j = 0; j < (long long)m; j++) {
      MAP[i][j] = s[j] - 'a';
    }
  }
  vector<vector<bool> > checked(n, vector<bool>(m, false));
  for (long long j = 0; j < (long long)m; j++) {
    int idx = 0;
    checked[0][j] = true;
    while (idx < n && MAP[idx + 1][j] == MAP[idx][j]) {
      idx++;
      if (idx >= n) break;
      checked[idx][j] = true;
    }
  }
  long long ans = 0;
  for (long long j = 0; j < (long long)m; j++) {
    for (long long i = 0; i < (long long)n; i++) {
      if (checked[i][j]) continue;
      ans = calc(i, j, ans, checked);
    }
  }
  cout << ans << ENDL;
}
