#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 3e18 + 1;
const char invdir[]{'L', 'U', 'R', 'D'};
const char dir[]{'R', 'D', 'L', 'U'};
const int dx[]{0, 1, 0, -1};
const int dy[]{1, 0, -1, 0};
unsigned get_seed() {
  unsigned seed = chrono::system_clock::now().time_since_epoch().count();
  return seed;
}
const int MOD = 1000000007;
const int NMAX = 1000777;
int n, m;
char t[2555][2555];
int dp[2555][2555];
int solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> t[i][j];
    }
  }
  long long rs = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i - 1][j + 1])) + 1;
      if (t[i][j] != t[i - 1][j - 1]) dp[i][j] = 1;
      if (t[i][j] != t[i - 1][j + 1]) dp[i][j] = 1;
      if (t[i][j] != t[i - 1][j]) dp[i][j] = 1;
      if (dp[i][j] > 1 && t[i - (dp[i][j] - 1) * 2][j] != t[i][j]) {
        dp[i][j]--;
      }
      rs += dp[i][j];
    }
  }
  cout << rs << "\n";
  return 0;
}
int main() {
  cout << setprecision(16);
  cin.tie(0);
  std::ios_base::sync_with_stdio(0);
  int T = 1;
  int i = 1;
  while (T--) {
    solve();
    i++;
  }
  return 0;
}
