#include <bits/stdc++.h>
using namespace std;
const unsigned long long maxn = 2000 + 10;
string ss[maxn];
vector<unsigned long long> vc;
unsigned long long a[maxn][maxn];
unsigned long long dp[maxn][maxn];
unsigned long long n, m;
unsigned long long make1() {
  unsigned long long ans = 0;
  for (unsigned long long j = 1; j <= m; j++) {
    vc.clear();
    unsigned long long t = 1;
    for (unsigned long long i = 1; i <= n; i++) {
      if (a[i + 1][j] == a[i][j]) {
        t++;
      } else {
        vc.push_back(t);
        t = 1;
      }
    }
    unsigned long long num = 0;
    for (unsigned long long i = 0; i + 2 < vc.size(); i++) {
      if (vc[i] >= vc[i + 1] && vc[i + 1] <= vc[i + 2]) {
        unsigned long long r = num + vc[i] + vc[i + 1] + vc[i + 1];
        unsigned long long l = r - 3 * vc[i + 1] + 1;
        unsigned long long flag = 0;
        for (unsigned long long k = l; k <= r; k++) {
          if (a[k][j] != a[k][j - 1]) {
            flag = 1;
            break;
          }
        }
        if (flag == 1)
          dp[r][j] = 1;
        else
          dp[r][j] = dp[r][j - 1] + 1;
        ans += dp[r][j];
      }
      num += vc[i];
    }
  }
  return ans;
}
int32_t main() {
  cin >> n >> m;
  for (unsigned long long i = 0; i < n; i++) cin >> ss[i];
  for (unsigned long long i = 0; i < n; i++) {
    for (unsigned long long j = 0; j < m; j++) {
      a[i + 1][j + 1] = ss[i][j] - 'a' + 1;
    }
  }
  unsigned long long ans = 0;
  ans += make1();
  cout << ans << endl;
}
