#include <bits/stdc++.h>
const long long MOD = 1000000007;
const long long inf = 1000000000000000000;
using namespace std;
int n, q, n1;
long long int modpow(long long int x, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
long long int power(long long int x, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
void solve() {
  int n, m;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  vector<vector<long long int>> dp1(n, std::vector<long long int>(m, 1)),
      dp2(n, std::vector<long long int>(m, 1)),
      dp3(n, std::vector<long long int>(m, 1)),
      dp4(n, std::vector<long long int>(m, 1));
  vector<vector<long long int>> d1(n, std::vector<long long int>(m, 1)),
      d2(n, std::vector<long long int>(m, 1));
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= m - 1; j++) {
      if (s[i][j] == s[i][j - 1]) dp1[i][j] = dp1[i][j - 1] + 1;
    }
    for (int j = m - 2; j >= 0; j--) {
      if (s[i][j] == s[i][j + 1]) dp2[i][j] = dp2[i][j + 1] + 1;
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 1; i <= n - 1; i++) {
      if (s[i][j] == s[i - 1][j]) dp3[i][j] = dp3[i - 1][j] + 1;
    }
    for (int i = n - 2; i >= 0; i--) {
      if (s[i][j] == s[i + 1][j]) dp4[i][j] = dp4[i + 1][j] + 1;
    }
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= m - 1; j++) {
      if (s[i][j] != s[i][j - 1]) continue;
      d1[i][j] = min(d1[i][j - 1] + 1, min(dp3[i][j], dp4[i][j]));
    }
    for (int j = m - 2; j >= 0; j--) {
      if (s[i][j] != s[i][j + 1]) continue;
      d2[i][j] = min(d2[i][j + 1] + 1, min(dp3[i][j], dp4[i][j]));
    }
    for (int j = 0; j < m; j++) ans += min(d1[i][j], d2[i][j]);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t = 1, tt = 1;
  while (tt <= t) {
    solve();
    tt++;
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
