#include <bits/stdc++.h>
using namespace std;
int solve(int u, int v, int n, int m, vector<vector<int> > &r,
          vector<vector<int> > &c) {
  int d1, d2, d3, r1 = INT_MAX;
  d1 = c[u][v];
  if (d1 + u > n) return 0;
  d2 = c[u + d1][v];
  if (u + d1 + d2 > n) return 0;
  d3 = c[u + d1 + d2][v];
  if (d1 != d2 || d3 < d1) return 0;
  for (int i = u; i < u + 3 * d1; i++) r1 = min(r1, r[i][v]);
  return r1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> x(n + 1);
  for (int i = 1; i < n + 1; i++) {
    cin >> x[i];
    x[i] = '_' + x[i];
  }
  vector<vector<int> > row(n + 1, vector<int>(m + 1, 0)),
      col(n + 1, vector<int>(m + 1, 0));
  for (int i = 1; i < n + 1; i++) {
    int cur = 1;
    row[i][m] = 1;
    for (int j = m - 1; j >= 1; j--) {
      if (x[i][j] == x[i][j + 1])
        cur++;
      else
        cur = 1;
      row[i][j] = cur;
    }
  }
  for (int j = 1; j < m + 1; j++) {
    int cur = 1;
    col[n][j] = 1;
    for (int i = n - 1; i >= 1; i--) {
      if (x[i][j] == x[i + 1][j])
        cur++;
      else
        cur = 1;
      col[i][j] = cur;
    }
  }
  long long ans = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      ans += solve(i, j, n, m, row, col);
    }
  }
  cout << ans << endl;
  return 0;
}
