#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  char v1[n][m];
  vector<vector<long long> > v2(m, vector<long long>(1001, 0));
  vector<vector<long long> > f1(m, vector<long long>(1001, 0));
  vector<vector<string> > v3(m, vector<string>(1001));
  vector<vector<char> > v4(m);
  vector<vector<long long> > v5(m);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> v1[i][j];
    }
  }
  for (long long j = 0; j < m; j++) {
    for (long long i = 0; i < n; i++) {
      char c1 = v1[i][j];
      long long count = 0;
      while (i < n && v1[i][j] == c1) {
        i++;
        count++;
      }
      i--;
      v5[j].push_back(count);
      v4[j].push_back(c1);
    }
  }
  unordered_multiset<long long> st;
  for (long long j = 0; j < m; j++) {
    long long sum = 0;
    long long sz = v5[j].size();
    sz = sz - 3;
    for (long long i = 0; i <= sz; i++) {
      long long a1 = v5[j][i];
      long long a2 = v5[j][i + 1];
      long long a3 = v5[j][i + 2];
      if (a2 <= a1 && a2 <= a3) {
        long long a4 = a2;
        string s1;
        s1.push_back(v4[j][i]);
        s1.push_back(v4[j][i + 1]);
        s1.push_back(v4[j][i + 2]);
        long long sum1 = sum + a1 - a4;
        v2[j][sum1] = a4;
        v3[j][sum1] = s1;
        if (j != 0) {
          if (v2[j - 1][sum1] == a4 && v3[j - 1][sum1] == s1) {
            auto itr = st.find(f1[j - 1][sum1]);
            st.erase(itr);
            f1[j][sum1] = f1[j - 1][sum1] + 1;
            st.insert(f1[j][sum1]);
          } else {
            f1[j][sum1] = 1;
            st.insert(f1[j][sum1]);
          }
        } else {
          f1[j][sum1] = 1;
          st.insert(1);
        }
      }
      sum += v5[j][i];
    }
  }
  long long ans = 0;
  for (auto x : st) {
    long long a1 = ((x) * (x + 1)) / 2;
    ans += a1;
  }
  cout << ans << "\n";
}
