#include <bits/stdc++.h>
using namespace std;
const int MX = 2005;
int n, m, res[MX][MX], izq[MX][MX], der[MX][MX], arr[MX][MX], aba[MX][MX], acu;
int dp[MX][MX];
char c[MX][MX];
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
      res[i][j] = MX;
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      izq[i][j] = 1;
      if (j && c[i][j - 1] == c[i][j]) izq[i][j] += izq[i][j - 1];
    }
    for (int j = m - 1; j >= 0; j--) {
      der[i][j] = 1;
      if (j + 1 < m && c[i][j] == c[i][j + 1]) der[i][j] += der[i][j + 1];
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      arr[i][j] = 1;
      if (i && c[i - 1][j] == c[i][j]) arr[i][j] += arr[i - 1][j];
    }
    for (int i = n - 1; i >= 0; i--) {
      aba[i][j] = 1;
      if (i + 1 < n && c[i][j] == c[i + 1][j]) aba[i][j] += aba[i + 1][j];
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      dp[i][j] = min(izq[i][j], der[i][j]);
      if (i)
        dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
      else
        dp[i][j] = 1;
      res[i][j] = min(res[i][j], dp[i][j]);
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      dp[i][j] = min(aba[i][j], arr[i][j]);
      if (j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
      res[i][j] = min(res[i][j], dp[i][j]);
    }
  for (int i = n - 1; i >= 0; i--)
    for (int j = m - 1; j >= 0; j--) {
      dp[i][j] = min(izq[i][j], der[i][j]);
      if (i + 1 < n)
        dp[i][j] = min(dp[i][j], dp[i + 1][j] + 1);
      else
        dp[i][j] = 1;
      res[i][j] = min(res[i][j], dp[i][j]);
    }
  for (int i = n - 1; i >= 0; i--)
    for (int j = m - 1; j >= 0; j--) {
      dp[i][j] = min(aba[i][j], arr[i][j]);
      if (j + 1 < m)
        dp[i][j] = min(dp[i][j], dp[i][j + 1] + 1);
      else
        dp[i][j] = 1;
      res[i][j] = min(res[i][j], dp[i][j]);
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) acu += res[i][j];
  cout << acu << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
