#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < 0) a = -a;
  if (b < 0) b = -b;
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
void read(T &res) {
  bool flag = false;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') && (flag = true);
  for (res = ch - 48; isdigit(ch = getchar());
       res = (res << 1) + (res << 3) + ch - 48)
    ;
  flag && (res = -res);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long qp(long long a, long long b, long long mod) {
  long long ans = 1;
  if (b == 0) {
    return ans % mod;
  }
  while (b) {
    if (b % 2 == 1) {
      b--;
      ans = ans * a % mod;
    }
    a = a * a % mod;
    b = b / 2;
  }
  return ans % mod;
}
long long qpn(long long a, long long b, long long p) {
  long long ans = 1;
  a %= p;
  while (b) {
    if (b & 1) {
      ans = (ans * a) % p;
      --b;
    }
    a = (a * a) % p;
    b >>= 1;
  }
  return ans % p;
}
char s[2020][2010];
long long dp[2020][2020];
long long n, m;
bool check(long long x, long long y) {
  long long ok = x - 2;
  if (ok > 0 && y > 1 && y < m && s[x - 1][y] == s[x][y] &&
      s[x - 2][y] == s[x][y] && s[x][y] == s[x - 1][y - 1] &&
      s[x][y] == s[x - 1][y + 1]) {
    return true;
  }
  return false;
}
signed main() {
  read(n);
  read(m);
  for (long long i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      dp[i][j] = 1;
      if (check(i, j)) {
        dp[i][j] = min(dp[i - 2][j], min(dp[i - 1][j - 1], dp[i - 1][j + 1])) +
                   dp[i][j];
        ans = ans + dp[i][j];
        continue;
      }
      ans = ans + dp[i][j];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
