#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
char s[N][N];
int h[N][N];
pair<int, pair<char, pair<char, char> > > v[N];
void solve() {
  int n, m;
  scanf("%d %d ", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s[i] + 1);
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n;) {
      int k = i;
      for (; k <= n; ++k) {
        if (s[k][j] != s[i][j]) {
          break;
        }
      }
      int gg = k;
      for (k = i; k <= n; ++k) {
        if (s[k][j] != s[i][j]) {
          break;
        }
        h[k][j] = gg - k;
      }
      i = k;
    }
  }
  long long ret = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int height = h[i][j];
      if (i + height * 2 <= n && h[i + height][j] == height &&
          h[i + height + height][j] >= height) {
        v[j] = make_pair(height,
                         make_pair(s[i][j], make_pair(s[i + height][j],
                                                      s[i + height * 2][j])));
      } else {
        v[j] = make_pair(-1, make_pair(0, make_pair(0, 0)));
      }
    }
    for (int j = 1; j <= m;) {
      if (v[j].first <= 0) {
        ++j;
        continue;
      }
      int k;
      for (k = j; k <= m; ++k) {
        if (v[k] != v[j]) {
          break;
        }
      }
      int len = k - j;
      ret += len * (len + 1);
      j = k;
    }
  }
  ret /= 2;
  cout << ret << endl;
}
int main() { solve(); }
