#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e3 + 10;
int n, m, down[MAXN][MAXN];
char c[MAXN][MAXN];
void calc_down() {
  for (int j = 0; j < m; j++) {
    for (int i = n - 1; i >= 0; i--) {
      if (i == n - 1 || c[i][j] != c[i + 1][j])
        down[i][j] = 1;
      else
        down[i][j] = down[i + 1][j] + 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> c[i][j];
  }
  calc_down();
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int k = 0, len = 0;
    for (int j = 0; j < m; j++) {
      if (down[i][j] != k || i + 2 * k >= n || down[i + k][j] != k ||
          down[i + 2 * k][j] < k || c[i][j] != c[i][j - 1] ||
          c[i + k][j] != c[i + k][j - 1] ||
          c[i + 2 * k][j] != c[i + 2 * k][j - 1]) {
        ans += (long long)len * (len + 1) / 2;
        k = down[i][j];
        len = 1;
        if (i + 2 * k >= n || down[i + k][j] != k || down[i + 2 * k][j] < k) {
          k = 0;
          len = 0;
        }
      } else
        len++;
    }
    ans += (long long)len * (len + 1) / 2;
  }
  cout << ans;
  return 0;
}
