#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000 + 10;
long long INF = 1e9 + 10;
long long MOD = 998244353;
int n, m;
char c[MAXN][MAXN];
int up[MAXN][MAXN], down[MAXN][MAXN];
int l_half[MAXN][MAXN], r_half[MAXN][MAXN];
void precalc() {
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      up[i][j] = 1;
      if (i > 0 && c[i][j] == c[i - 1][j]) up[i][j] += up[i - 1][j];
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = n - 1; i >= 0; i--) {
      down[i][j] = 1;
      if (i < n - 1 && c[i][j] == c[i + 1][j]) down[i][j] += down[i + 1][j];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> c[i][j];
  }
  precalc();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j > 0 && c[i][j] == c[i][j - 1])
        l_half[i][j] = min({l_half[i][j - 1] + 1, up[i][j], down[i][j]});
      else
        l_half[i][j] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j >= 0; j--) {
      if (j < m - 1 && c[i][j] == c[i][j + 1])
        r_half[i][j] = min({r_half[i][j + 1] + 1, up[i][j], down[i][j]});
      else
        r_half[i][j] = 1;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) ans += min(l_half[i][j], r_half[i][j]);
  }
  cout << ans << '\n';
  return 0;
}
