#include <bits/stdc++.h>
using namespace std;
char a[2009][2009] = {0};
long long int dp1[2009][2009] = {0};
long long int dp2[2009][2009] = {0};
long long int dp3[2009][2009] = {0};
long long int dp4[2009][2009] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  string s;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 1; j <= m; j++) a[i][j] = s[j - 1];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp1[i][j] = 1;
      if (a[i - 1][j] == a[i][j] and a[i][j] == a[i][j - 1])
        dp1[i][j] = min(dp1[i - 1][j], dp1[i][j - 1]) + 1;
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      dp3[i][j] = 1;
      if (a[i + 1][j] == a[i][j] and a[i][j] == a[i][j - 1])
        dp3[i][j] = min(dp3[i + 1][j], dp3[i][j - 1]) + 1;
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      dp2[i][j] = 1;
      if (a[i + 1][j] == a[i][j] and a[i][j] == a[i][j + 1])
        dp2[i][j] = min(dp2[i + 1][j], dp2[i][j + 1]) + 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      dp4[i][j] = 1;
      if (a[i - 1][j] == a[i][j] and a[i][j] == a[i][j + 1])
        dp4[i][j] = min(dp4[i - 1][j], dp4[i][j + 1]) + 1;
    }
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ans += min(dp1[i][j], min(dp2[i][j], min(dp3[i][j], dp4[i][j])));
    }
  }
  cout << ans;
}
