#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll N = 3e3 + 5;
const ll M = 3e5 + 5;
char s[N][N];
ll l[N][N], r[N][N];
void solve() {
  ll n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> (s[i] + 1);
  }
  for (ll i = 1; i <= n; i++) {
    l[i][m] = 1;
    for (ll j = m - 1; j >= 1; j--) {
      if (s[i][j] == s[i][j + 1]) {
        l[i][j] = l[i][j + 1] + 1;
      } else
        l[i][j] = 1;
    }
  }
  for (ll j = 1; j <= m; j++) {
    r[n][j] = 1;
    for (ll i = n - 1; i >= 1; i--) {
      if (s[i][j] == s[i + 1][j]) {
        r[i][j] = r[i + 1][j] + 1;
      } else
        r[i][j] = 1;
    }
  }
  ll rs = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= m; j++) {
      ll h = r[i][j];
      ll h2 = i + h;
      if (r[h2][j] != h) {
        continue;
      }
      ll h3 = h2 + h;
      if (r[h3][j] >= h) {
        h3 = h3 + h - 1;
        ll mn = m;
        for (ll k = i; k <= h3; k++) {
          mn = min(mn, l[k][j]);
        }
        rs += mn;
      }
    }
  }
  cout << rs;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
