#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 1LL << 62;
const long long mx = 100005;
const double eps = 1e-10;
long long dx[10] = {1, 0, -1, 0};
long long dy[10] = {0, -1, 0, 1};
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long x = power(a, b / 2);
  x = x * x;
  if (b % 2) x = x * a;
  return x;
}
long long bigmod(long long a, long long b) {
  if (b == 0) return 1;
  long long x = bigmod(a, b / 2) % mod;
  x = (x * x) % mod;
  if (b % 2) x = (x * a) % mod;
  return x;
}
long long Set(long long N, long long pos) { return N = N | (1LL << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1LL << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1LL << pos)); }
char grid[2005][2005];
long long dp[2005][2005];
bool ck(long long x, long long y) {
  bool res = 1;
  for (long long i = 0; i < 4; i++) {
    long long a = x + dx[i];
    long long b = y + dy[i];
    if (grid[x][y] != grid[a][b]) return res = 0;
  }
  return res;
}
char str[2005];
int main() {
  long long tst, a, b, c, k, n, m, res = 0, ans = 0, t = 0;
  scanf("%lld", &n), scanf("%lld", &m);
  for (long long i = 1; i <= n; i++) {
    scanf(" %s", str + 1);
    for (long long j = 1; j <= m; j++) {
      grid[i][j] = str[j];
    }
  }
  deque<long long> q;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (ck(i, j)) {
        dp[i][j] = -1;
      } else {
        q.push_back(i), q.push_back(j);
        dp[i][j] = 1;
      }
    }
  }
  while (!q.empty()) {
    a = q.front();
    q.pop_front();
    b = q.front();
    q.pop_front();
    res += dp[a][b];
    for (long long i = 0; i < 4; i++) {
      c = a + dx[i];
      long long d = b + dy[i];
      if (dp[c][d] == -1 and grid[a][b] == grid[c][d]) {
        dp[c][d] = 1 + dp[a][b];
        q.push_back(c);
        q.push_back(d);
      }
    }
  }
  cout << res << "\n";
  return 0;
}
