#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const std::string letters = "aeiou";
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  for (auto &line : a) {
    cin >> line;
  }
  vector<vector<int>> len(n, vector<int>(m));
  for (int j = 0; j < m; ++j) {
    len[n - 1][j] = 1;
    for (int i = n - 2; i >= 0; --i) {
      len[i][j] = 1;
      if (a[i][j] == a[i + 1][j]) {
        len[i][j] += len[i + 1][j];
      }
    }
  }
  ll ans = 0;
  vector<int> flaglen(n);
  vector<int> flagwid(n);
  for (int j = 0; j < m; ++j) {
    for (int i = 0; i < n; ++i) {
      int l = len[i][j];
      if (i + 2 * l < n && len[i + l][j] == l && len[i + 2 * l][j] >= l) {
      } else {
        l = 0;
      }
      ans += ll(flagwid[i]);
      if (l && flaglen[i] == l &&
          (j == 0 ||
           (a[i][j - 1] == a[i][j] && a[i + l][j - 1] == a[i + l][j] &&
            a[i + 2 * l][j - 1] == a[i + 2 * l][j]))) {
        ++flagwid[i];
      } else {
        flaglen[i] = l;
        if (l) {
          flagwid[i] = 1;
        } else {
          flagwid[i] = 0;
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    ans += ll(flagwid[i]);
  }
  cout << ans << endl;
  return 0;
}
