#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
char g[N][N];
long long r[N][N], c[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> (g[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (g[i][j] == g[i][j - 1])
        r[i][j] = r[i][j - 1] + 1;
      else
        r[i][j] = 1;
    }
  }
  for (int i = n; i > 0; i--) {
    for (int j = 1; j <= m; j++) {
      if (g[i][j] == g[i + 1][j])
        c[i][j] = c[i + 1][j] + 1;
      else
        c[i][j] = 1;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      int d = c[j][i];
      if (j + 3 * d <= n + 1 && c[j + d][i] == d && c[j + 2 * d][i] >= d) {
        long long mi = 1e9;
        for (int k = j; k < j + 3 * d; k++) {
          mi = min(mi, r[k][i]);
        }
        ans += mi;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
