#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long hell = round(1e18);
signed solve() {
  long long m, n;
  cin >> n >> m;
  vector<vector<long long> > v(n + 2, vector<long long>(m + 2, -1));
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      char ch;
      cin >> ch;
      v[i][j] = ch - '0';
    }
  }
  vector<vector<long long> > up(n + 2, vector<long long>(m + 2, 1));
  vector<vector<long long> > dn(n + 2, vector<long long>(m + 2, 1));
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (v[i][j] == v[i - 1][j]) up[i][j] = up[i - 1][j] + 1;
      if (v[n + 1 - i][j] == v[n + 2 - i][j])
        dn[n + 1 - i][j] = dn[n + 2 - i][j] + 1;
    }
  }
  vector<vector<long long> > l(n + 2, vector<long long>(m + 2, 1));
  vector<vector<long long> > r(n + 2, vector<long long>(m + 2, 1));
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (v[i][j] == v[i][j - 1])
        l[i][j] = min(l[i][j - 1] + 1, min(up[i][j], dn[i][j]));
      if (v[i][m + 1 - j] == v[i][m + 2 - j])
        r[i][m + 1 - j] =
            min(r[i][m + 2 - j] + 1, min(up[i][m + 1 - j], dn[i][m + 1 - j]));
    }
  }
  vector<vector<long long> > a(n + 2, vector<long long>(m + 2, 1));
  long long sm = 0;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      a[i][j] = min(l[i][j], r[i][j]);
      sm += a[i][j];
    }
  }
  cout << sm;
  return 0;
}
signed main() {
  long long t = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  while (t--) {
    solve();
  }
  return 0;
}
