#include <bits/stdc++.h>
using namespace std;
bool cmpr(pair<long long int, long long int> a,
          pair<long long int, long long int> b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (long long int i = 0; i < n; i++) {
    cin >> s[i];
  }
  vector<vector<long long int>> dp1(n, vector<long long int>(m, 1)), dp2, dp3,
      dp4, dp5;
  dp2 = dp1;
  dp3 = dp1;
  dp4 = dp1;
  long long int a = 0;
  for (long long int i = 1; i < n; i++) {
    for (long long int j = 1; j < m; j++) {
      if (s[i][j] == s[i - 1][j] && s[i][j] == s[i][j - 1]) {
        dp1[i][j] = min(dp1[i - 1][j], dp1[i][j - 1]) + 1;
      }
    }
  }
  for (long long int i = n - 2; i >= 0; i--) {
    for (long long int j = m - 2; j >= 0; j--) {
      if (s[i][j] == s[i + 1][j] && s[i][j] == s[i][j + 1]) {
        dp2[i][j] = min(dp2[i + 1][j], dp2[i][j + 1]) + 1;
      }
    }
  }
  for (long long int i = 1; i < n; i++) {
    for (long long int j = m - 2; j >= 0; j--) {
      if (s[i][j] == s[i - 1][j] && s[i][j] == s[i][j + 1]) {
        dp3[i][j] = min(dp3[i - 1][j], dp3[i][j + 1]) + 1;
      }
    }
  }
  for (long long int i = n - 2; i >= 0; i--) {
    for (long long int j = 1; j < m; j++) {
      if (s[i][j] == s[i + 1][j] && s[i][j] == s[i][j - 1]) {
        dp4[i][j] = min(dp4[i + 1][j], dp4[i][j - 1]) + 1;
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      a += min(min(dp1[i][j], dp2[i][j]), min(dp3[i][j], dp4[i][j]));
    }
  }
  cout << a << endl;
}
