#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using ll = long long;
using ull = unsigned long long;
int n, m;
vector<string> field;
int nextDown(int r, int c) {
  for (int i = r + 1; i < n; ++i)
    if (field[i][c] != field[r][c]) return i;
  return n;
}
int nextRight(int r, int c) {
  for (int i = c + 1; i < m; ++i)
    if (field[r][i] != field[r][c]) return i;
  return m;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  field.assign(n, string());
  for (int i = 0; i < n; ++i) cin >> field[i];
  ll res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int i1 = nextDown(i, j);
      int i2 = nextDown(i1, j);
      int i3 = nextDown(i2, j);
      if (i1 - i == i2 - i1 && i3 - i2 >= i2 - i1) {
        int cur = m;
        for (int k = 0; k < (i1 - i) * 3; ++k)
          cur = min(cur, nextRight(i + k, j));
        res += cur - j;
        res = res;
      }
    }
  }
  cout << res << endl;
  return 0;
}
