#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, j, cnt;
  cin >> n >> m;
  long long int dp[n + 10][m + 10];
  string s[n + 10];
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  cnt = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (i == 0 or i == 1 or j == 0 or j == m - 1) {
        dp[i][j] = 1;
      } else if (s[i][j] != s[i - 1][j - 1] or s[i][j] != s[i - 1][j] or
                 s[i][j] != s[i - 1][j + 1] or s[i][j] != s[i - 2][j]) {
        dp[i][j] = 1;
      } else {
        dp[i][j] =
            min(dp[i - 1][j - 1], min(dp[i - 2][j], dp[i - 1][j + 1])) + 1;
      }
      cnt += dp[i][j];
    }
  }
  cout << cnt << endl;
}
