#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 1 << 10;
const long double pi = 3.14159265;
long long n, m, k[N][N], ans[N][N], res;
char u[N][N];
bool c(long long x, long long y) {
  long long t1 = x - k[x][y], t2 = t1 - k[t1][y];
  if (t1 < 0 || t2 < 0) return 0;
  if (k[t1][y] == k[x][y] && k[t1][y] <= k[t2][y]) return 1;
  return 0;
}
bool b(long long x, long long y, long long px, long long py) {
  if ((!c(x, y)) || (!c(px, py))) return 0;
  if (u[x][y] != u[px][py] || k[x][y] != k[px][py]) return 0;
  x = x - k[x][y];
  px = px - k[px][py];
  if (u[x][y] != u[px][py] || k[x][y] != k[px][py]) return 0;
  x -= k[x][y];
  px -= k[px][py];
  if (u[x][y] != u[px][py]) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> u[i][j];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      if (u[i][j] == u[i - 1][j])
        k[i][j] = k[i - 1][j] + 1;
      else
        k[i][j] = 1;
    }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (c(i, j)) ans[i][j] = 1;
      if (b(i, j, i, j - 1) && j > 0) ans[i][j] += ans[i][j - 1];
    }
  }
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) res += ans[i][j];
  cout << res;
  return 0;
}
