#include <bits/stdc++.h>
using namespace std;
char c[1005][1005];
long long L[1005][1005];
long long mx[1005][1005];
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= m; ++j) {
      cin >> c[i][j];
    }
  }
  long long ans = 0;
  for (long long j = 1; j <= m; ++j) {
    long long le = 1;
    long long fl = 0;
    long long s1 = 0;
    long long s2 = 0;
    long long L1 = 1;
    long long L2 = 1;
    long long L3 = 1;
    for (long long i = n; i >= 1; --i) {
      if (c[i][j] == c[i][j - 1]) {
        L[i][j] = L[i][j - 1];
      } else {
        L[i][j] = j;
      }
      if (i == n || c[i][j] != c[i + 1][j])
        mx[i][j] = L[i][j];
      else
        mx[i][j] = max(mx[i][j], max(L[i][j], mx[i + 1][j]));
    }
    for (long long i = 1; i <= n; ++i) {
      if (c[i][j] != c[i - 1][j]) {
        fl++;
        if (fl == 2) {
          s1 = le;
          L1 = L3;
        } else if (fl == 3) {
          s2 = le;
          L2 = L3;
        } else if (fl > 3) {
          s1 = s2;
          s2 = le;
          L1 = L2;
          L2 = L3;
        }
        le = 1;
        L3 = 1;
      } else {
        le++;
      }
      L3 = max(L[i][j], L3);
      if (fl >= 3 && s1 >= s2 && s2 == le) {
        long long L4 = max(mx[i - s2 * 3 + 1][j], max(L2, L3));
        ans += (j - L4 + 1);
      }
    }
  }
  cout << ans << endl;
}
