#include <bits/stdc++.h>
using i8 = char;
using u8 = unsigned char;
using i16 = short int;
using u16 = unsigned short int;
using i32 = int;
using u32 = unsigned int;
using i64 = long long int;
using u64 = unsigned long long int;
using f32 = float;
using f64 = double;
using f80 = long double;
const i64 MOD = 1000000007;
const f64 EPS = 1e-9;
inline i64 fast_pow(i64 a, i64 b) {
  i64 ans = 1, base = a;
  while (b) {
    if (b & 1) {
      ans = (ans * base) % MOD;
    }
    base = (base * base) % MOD;
    b >>= 1;
  }
  return ans;
}
using namespace std;
inline u64 count(u64 w) { return w * (w + 1) / 2; }
unordered_map<string, set<pair<u64, u64>>> d;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  u64 n, m;
  cin >> n >> m;
  array<string, 1001> s;
  for (u64 i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (u64 j = 0; j < m; ++j) {
    array<pair<char, u64>, 3> c;
    u64 z = 0;
    for (u64 i = 0; i < n; ++i) {
      if (z < 3) {
        if (z == 0) {
          c[z].first = s[i][j];
          c[z].second = 1;
          ++z;
        } else {
          if (s[i][j] == c[z - 1].first) {
            c[z - 1].second += 1;
          } else {
            c[z].first = s[i][j];
            c[z].second = 1;
            ++z;
          }
        }
      } else {
        if (s[i][j] == c[2].first) {
          c[2].second += 1;
        } else {
          c[0] = c[1];
          c[1] = c[2];
          c[2].first = s[i][j];
          c[2].second = 1;
        }
      }
      if (z > 2 && c[1].second == c[2].second && c[0].second >= c[1].second) {
        u64 ind = (i + 1) - c[2].second * 3;
        string tmp = "";
        for (u64 k = 0; k < 3; ++k)
          for (u64 b = 0; b < c[2].second; ++b) tmp += c[k].first;
        d[tmp].emplace(ind, j);
      }
    }
  }
  u64 res = 0;
  for (auto const &s : d) {
    u64 li = s.second.begin()->first;
    u64 lj = s.second.begin()->second;
    u64 cc = 1;
    for (auto it = std::next(s.second.cbegin()); it != s.second.cend(); ++it) {
      if (it->first == li && it->second == lj + 1) {
        lj = it->second;
        ++cc;
      } else {
        res += count(cc);
        li = it->first;
        lj = it->second;
        cc = 1;
      }
    }
    res += count(cc);
  }
  cout << res << "\n";
  return 0;
}
