#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int M = 1000000007;
long long int inv(long long int a, long long int b) {
  return 1 < a ? b - inv(b % a, a) * b / a : 1;
}
pair<long long int, long long int> neigh[4] = {
    {-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  cin >> n;
  long long int m;
  cin >> m;
  string ar[n];
  for (long long int i = 0; i < (n); i++) cin >> ar[i];
  long long int res[n][m];
  queue<pair<long long int, long long int> > q;
  bool visited[n][m];
  for (long long int i = 0; i < (n); i++) {
    for (long long int j = 0; j < (m); j++) {
      visited[i][j] = false;
      res[i][j] = LLONG_MAX;
      if ((i == 0 || i == n - 1) || (j == 0 || j == m - 1) ||
          ar[i + 1][j + 0] != ar[i][j] || ar[i + -1][j + 0] != ar[i][j] ||
          ar[i + 0][j + -1] != ar[i][j] || ar[i + 0][j + 1] != ar[i][j]) {
        res[i][j] = 1;
        q.push({i, j});
        visited[i][j] = true;
      }
    }
  }
  while (!q.empty()) {
    pair<long long int, long long int> cur = q.front();
    q.pop();
    for (long long int i = 0; i < (4); i++) {
      if (!(cur.first + neigh[i].first >= 0 &&
            cur.first + neigh[i].first < n) ||
          !(cur.second + neigh[i].second >= 0 &&
            cur.second + neigh[i].second < m))
        continue;
      if (!visited[cur.first + neigh[i].first][cur.second + neigh[i].second]) {
        res[cur.first + neigh[i].first][cur.second + neigh[i].second] =
            res[cur.first][cur.second] + 1;
        visited[cur.first + neigh[i].first][cur.second + neigh[i].second] =
            true;
        q.push({cur.first + neigh[i].first, cur.second + neigh[i].second});
      }
    }
  }
  long long int sum = 0;
  for (long long int i = 0; i < (n); i++) {
    for (long long int j = 0; j < (m); j++) {
      sum += res[i][j];
    }
  }
  cout << sum << endl;
}
