#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 20;
const long long inf = 1e16;
long long powm(long long x, long long y, long long m = 1000000007) {
  x = x % m;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
long long modinv(long long a, long long m = 1000000007) {
  return powm(a, m - 2, m);
}
void mkr() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
}
int32_t main() {
  mkr();
  long long n;
  cin >> n;
  long long m;
  cin >> m;
  vector<string> s(n);
  for (long long i = 0; i < n; i++) cin >> s[i];
  vector<vector<long long> > a(n, vector<long long>(m, 1));
  for (long long i = 2; i <= n - 1; i++) {
    for (long long j = 1; j <= m - 2; j++) {
      {
        if ((s[i][j] == s[i - 1][j - 1]) and (s[i][j] == s[i - 1][j + 1]) and
            (s[i][j] == s[i - 1][j]) and (s[i][j] == s[i - 2][j]))
          a[i][j] = min({a[i - 1][j - 1], a[i - 1][j], a[i - 2][j],
                         a[i - 1][j + 1]}) +
                    1;
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += accumulate(a[i].begin(), a[i].end(), 0ll);
  }
  cout << ans;
  cout << "\n";
}
