#include <bits/stdc++.h>
using namespace std;
long long t, n, i, j, k, x, y, z, l, r, mid, ans, mod = 1e9 + 7, g, m;
long long b[2002][2005], d[2002][2005];
char ch, a[2002][2002];
string s, st;
vector<long long> v[300005], u;
long long dp(int i, int j) {
  long long &ret = d[i][j];
  if (ret) return ret;
  if (i + 1 == n || j - 1 < 0 || j + 1 == m || a[i + 1][j + 1] != a[i][j] ||
      a[i + 1][j - 1] != a[i][j])
    return ret = 1;
  ret = min({(b[i][j] + 1) / 2, 1 + dp(i + 1, j + 1), 1 + dp(i + 1, j - 1)});
  return ret;
}
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  for (i = n - 1; i >= 0; i--)
    for (j = 0; j < m; j++) {
      b[i][j] = 1;
      if (a[i + 1][j] == a[i][j]) b[i][j] += b[i + 1][j];
    }
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) ans += dp(i, j);
  cout << ans;
}
