#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  ;
  cin.tie(NULL);
  ;
  long long int t = 1;
  while (t--) {
    long long int n, m, i, j, k;
    cin >> n >> m;
    vector<string> v(n);
    for (i = 0; i < n; i++) cin >> v[i];
    vector<vector<pair<long long int, char>>> cnt(
        n + 1, vector<pair<long long int, char>>(m + 1, {0, '@'}));
    for (i = 1; i <= m; i++) {
      for (j = 1; j <= n; j++) {
        cnt[j][i].first = 1;
        cnt[j][i].second = v[j - 1][i - 1];
        if (j - 2 >= 0 && v[j - 2][i - 1] == v[j - 1][i - 1])
          cnt[j][i].first += cnt[j - 1][i].first;
      }
    }
    long long int ans = 0;
    vector<vector<pair<long long int, long long int>>> dp(
        n + 1, vector<pair<long long int, long long int>>(m + 1, {0, 0}));
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        pair<long long int, char> p1, p2, p3;
        p1 = {cnt[i][j].first, cnt[i][j].second};
        if (i - p1.first >= 0)
          p2 = {cnt[i - p1.first][j].first, cnt[i - p1.first][j].second};
        else
          continue;
        if (p1.first != p2.first || p1.second == p2.second) continue;
        if (i - 2 * p1.first >= 0)
          p3 = {cnt[i - 2 * p1.first][j].first,
                cnt[i - 2 * p1.first][j].second};
        else
          continue;
        if (p1.first > p3.first || p2.second == p3.second) continue;
        if (p1.first == dp[i][j - 1].first &&
            (p1.second == cnt[i][j - 1].second &&
             p2.second == cnt[i - p1.first][j - 1].second &&
             p3.second == cnt[i - 2 * p1.first][j - 1].second)) {
          dp[i][j] = dp[i][j - 1];
          dp[i][j].second++;
          ans += dp[i][j].second;
        } else {
          dp[i][j] = {p1.first, 1ll};
          ans++;
        }
      }
    }
    cout << ans << "\n";
  }
}
