#include <bits/stdc++.h>
using namespace std;
int N, M;
string A[2005];
long long DPL[2005][2005], DPR[2005][2005];
long long ans;
long long U[2005][2005], D[2005][2005];
void pre() {
  for (int j = 0; j <= M - 1; j++) U[0][j] = 1;
  for (int i = 1; i <= N - 1; i++) {
    for (int j = 0; j <= M - 1; j++) {
      if (A[i][j] == A[i - 1][j])
        U[i][j] = U[i - 1][j] + 1;
      else
        U[i][j] = 1;
    }
  }
  for (int j = 0; j <= M - 1; j++) D[N - 1][j] = 1;
  for (int i = N - 2; i >= 0; i--) {
    for (int j = 0; j <= M - 1; j++) {
      if (A[i][j] == A[i + 1][j])
        D[i][j] = D[i + 1][j] + 1;
      else
        D[i][j] = 1;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i <= N - 1; i++) cin >> A[i];
  pre();
  for (int i = 0; i <= N - 1; i++) {
    DPL[i][0] = 1;
    for (int j = 1; j <= M - 1; j++) {
      if (A[i][j] == A[i][j - 1]) {
        DPL[i][j] = min(DPL[i][j - 1] + 1, min(U[i][j], D[i][j]));
      } else
        DPL[i][j] = 1;
    }
    DPR[i][M - 1] = 1;
    ans++;
    for (int j = M - 2; j >= 0; j--) {
      if (A[i][j] == A[i][j + 1]) {
        DPR[i][j] = min(DPR[i][j + 1] + 1, min(U[i][j], D[i][j]));
      } else
        DPR[i][j] = 1;
      ans += min(DPL[i][j], DPR[i][j]);
    }
  }
  cout << ans << '\n';
  return 0;
}
