#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using v = vector<T>;
template <typename... T>
using tup = tuple<T...>;
template <typename T1, typename T2>
using pa = pair<T1, T2>;
const ld PI = 3.1415926535;
const ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
void solve() {
  ll n, m;
  cin >> n >> m;
  v<string> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }
  v<v<ll>> sameSymbolCnt(n, v<ll>(m, 1));
  for (ll i = 0; i < n; ++i) {
    for (ll j = 1; j < m; ++j) {
      if (a[i][j] == a[i][j - 1]) {
        sameSymbolCnt[i][j] = sameSymbolCnt[i][j - 1] + 1;
      } else {
        sameSymbolCnt[i][j] = 1;
      }
    }
  }
  v<v<ll>> sameSymbolCntODir(n, v<ll>(m, 1));
  for (ll i = 0; i < n; ++i) {
    for (ll j = m - 2; j >= 0; --j) {
      if (a[i][j] == a[i][j + 1]) {
        sameSymbolCntODir[i][j] = sameSymbolCntODir[i][j + 1] + 1;
      } else {
        sameSymbolCntODir[i][j] = 1;
      }
    }
  }
  v<v<ll>> maxPieceSize = v<v<ll>>(n, v<ll>(m, 1));
  for (ll j = 0; j < m; ++j) {
    for (ll i = 1; i < n; ++i) {
      ll r = min(sameSymbolCnt[i][j], sameSymbolCntODir[i][j]);
      r = min(r, maxPieceSize[i - 1][j] + 1);
      if (a[i - 1][j] != a[i][j]) {
        r = 1;
      }
      maxPieceSize[i][j] = r;
    }
  }
  v<v<ll>> maxPieceSizeODir = v<v<ll>>(n, v<ll>(m, 1));
  for (ll j = 0; j < m; ++j) {
    for (ll i = n - 2; i >= 0; --i) {
      ll r = min(sameSymbolCnt[i][j], sameSymbolCntODir[i][j]);
      r = min(r, maxPieceSizeODir[i + 1][j] + 1);
      if (a[i + 1][j] != a[i][j]) {
        r = 1;
      }
      maxPieceSizeODir[i][j] = r;
    }
  }
  ll r = 0;
  for (ll i = 0; i < n; ++i) {
    for (ll j = 0; j < m; ++j) {
      r += min(maxPieceSize[i][j], maxPieceSizeODir[i][j]);
    }
  }
  cout << r;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll t = 1;
  for (ll i = 0; i < t; ++i) {
    solve();
  }
}
