#include <bits/stdc++.h>
const int N = 2005;
using namespace std;
int m, n;
int U[N][N], D[N][N];
int a[N][N], b[N][N];
int L[N], R[N];
long long res;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> n;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      char x;
      cin >> x;
      a[i][j] = x - 'a';
      if (a[i][j] == a[i - 1][j])
        U[i][j] = U[i - 1][j] + 1;
      else
        U[i][j] = 1;
    }
  }
  for (int i = m; i >= 1; i--) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] == a[i + 1][j])
        D[i][j] = D[i + 1][j] + 1;
      else
        D[i][j] = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      b[i][j] = min(U[i][j], D[i][j]);
      if (a[i][j] == a[i][j - 1])
        L[j] = min(L[j - 1] + 1, b[i][j]);
      else
        L[j] = 1;
    }
    for (int j = n; j >= 1; j--) {
      if (a[i][j] == a[i][j + 1])
        R[j] = min(R[j + 1] + 1, b[i][j]);
      else
        R[j] = 1;
      res += min(L[j], R[j]);
    }
  }
  cout << res;
}
