#include <bits/stdc++.h>
using namespace std;
void preprocess() {}
long long n, m;
struct triplet {
  char a, b, c;
  long long sza, szb, szc;
};
bool valid(triplet x) {
  return x.a != ' ' && x.b != ' ' && x.c != ' ' && x.sza != 0 && x.szb != 0 &&
         x.szc != 0 && x.szb <= min(x.sza, x.szc);
}
bool equals(triplet x, triplet y) {
  return x.a == y.a && x.b == y.b && x.c == y.c && x.szb == y.szb;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  clock_t clk = clock();
  preprocess();
  long long t = 1;
  while (t--) {
    cin >> n >> m;
    string s[n + 2];
    for (long long i = 1; i <= n; ++i) {
      cin >> s[i];
    }
    char emp[m];
    for (long long i = 0; i < m; i++) emp[i] = ' ';
    s[n + 1] = emp;
    s[0] = emp;
    long long ch1[n + 2][m];
    memset(ch1, 0, sizeof(ch1));
    for (long long j = 0; j < m; ++j) {
      long long cnt = 1;
      for (long long i = 1; i <= n; ++i) {
        if (s[i][j] != s[i + 1][j]) {
          ch1[i][j] = cnt;
          cnt = 1;
        } else {
          cnt++;
        }
      }
    }
    long long ch2[n + 2][m];
    memset(ch2, 0, sizeof(ch2));
    for (long long j = 0; j < m; ++j) {
      long long cnt = 1;
      for (long long i = n; i >= 1; --i) {
        if (s[i][j] != s[i - 1][j]) {
          ch2[i][j] = cnt;
          cnt = 1;
        } else {
          cnt++;
        }
      }
    }
    triplet save[n + 2][m];
    for (long long i = 1; i <= n; ++i) {
      for (long long j = 0; j < m; j++) {
        save[i][j].a = ' ';
        save[i][j].b = ' ';
        save[i][j].c = ' ';
        save[i][j].sza = 0;
        save[i][j].szb = 0;
        save[i][j].szc = 0;
      }
    }
    for (long long i = 1; i <= n; ++i) {
      for (long long j = 0; j < m; ++j) {
        if (ch1[i][j]) {
          save[i][j].a = s[i - ch1[i][j]][j];
          save[i][j].b = s[i][j];
          save[i][j].c = s[i + 1][j];
          save[i][j].sza = ch1[i - ch1[i][j]][j];
          save[i][j].szb = ch1[i][j];
          save[i][j].szc = ch2[i + 1][j];
        }
      }
    }
    long long ans = 0;
    for (long long i = 1; i <= n; ++i) {
      long long cnt = 0;
      for (long long j = 0; j < m; ++j) {
        if (ch1[i][j] && valid(save[i][j]) &&
            equals(save[i][j], save[i][j - 1])) {
          cnt++;
        } else if (valid(save[i][j])) {
          ans += (cnt * (cnt + 1)) / 2;
          cnt = 1;
        } else {
          ans += (cnt * (cnt + 1)) / 2;
          cnt = 0;
        }
      }
      if (cnt) {
        ans += (cnt * (cnt + 1)) / 2;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
