#include <bits/stdc++.h>
using namespace std;
char cs[1010];
int nxr[1010][1010];
int pc[26][1010][1010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<string> s(n);
  for (string &t : s) {
    scanf("%s", cs);
    t = cs;
  }
  for (int id = 0; id < 26; id++) {
    for (int j = 0; j < m; j++) {
      pc[id][j][0] = (s[0][j] == (id + 'a'));
      for (int i = 1; i < n; i++)
        pc[id][j][i] = pc[id][j][i - 1] + (s[i][j] == (id + 'a'));
    }
  }
  for (int j = 0; j < m; j++) {
    nxr[n - 1][j] = 1;
    for (int i = n - 2; i >= 0; i--) {
      nxr[i][j] = s[i][j] == s[i + 1][j] ? nxr[i + 1][j] + 1 : 1;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int l = 0; l < m; l++) {
      int h = nxr[i][l];
      if (i + (h * 3) > n) continue;
      int des = h;
      int id1 = s[i][l] - 'a';
      int id2 = s[i + h][l] - 'a';
      int id3 = s[i + 2 * h][l] - 'a';
      int cur1 = (id1 == id2 || id2 == id3 ? -(1 << 25) : 0), cur2 = 0,
          cur3 = 0;
      int r = l;
      while (r < m) {
        cur1 += pc[id1][r][i + h - 1];
        if (i) cur1 -= pc[id1][r][i - 1];
        cur2 += pc[id2][r][i + 2 * h - 1] - pc[id2][r][i + h - 1];
        cur3 += pc[id3][r][i + 3 * h - 1] - pc[id3][r][i + 2 * h - 1];
        if (cur1 != des || cur2 != des || cur3 != des) break;
        des += h;
        r++;
      }
      if (r - l) {
        long long len = r - l;
        ans += len * (len + 1) / 2;
        l = r - 1;
      }
    }
  }
  cout << ans << endl;
}
