#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int KINF = 0x3f3f3f3f;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  string g[n];
  for (int i = (int)0; i < (int)n; ++i) {
    cin >> g[i];
  }
  int dp[n][m];
  int ans = 0;
  for (int i = (int)0; i < (int)n; ++i)
    for (int j = (int)0; j < (int)m; ++j) {
      if (i <= 1 || j == 0 || j == m - 1 || g[i][j] != g[i - 1][j] ||
          g[i][j] != g[i - 1][j - 1] || g[i][j] != g[i - 1][j + 1] ||
          g[i][j] != g[i - 2][j])
        dp[i][j] = 1;
      else
        dp[i][j] = min({dp[i - 1][j - 1], dp[i - 1][j + 1], dp[i - 1][j],
                        dp[i - 2][j]}) +
                   1;
      ans += dp[i][j];
    }
  cout << ans << endl;
  return 0;
}
