#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 2;
char s[N][N];
int r[N][N], c[N][N];
long long dp[N][N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      c[i][j] = (s[i][j] == s[i - 1][j] ? c[i - 1][j] + 1 : 1);
      r[i][j] = (s[i][j] == s[i][j - 1] ? r[i][j - 1] + 1 : 1);
    }
  }
  long long ans = 0;
  for (int i = 3; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int upos = i - c[i][j] + 1 - 1;
      if (c[upos][j] != c[i][j]) continue;
      int uupos = upos - c[i][j] + 1 - 1;
      if (c[uupos][j] < c[i][j]) continue;
      dp[i][j] = 1;
      if (r[i][j - 1] + 1 == r[i][j]) {
        if (r[upos][j - 1] + 1 == r[upos][j] &&
            r[uupos][j - 1] + 1 == r[uupos][j]) {
          if (c[i][j - 1] == c[i][j] && c[upos][j - 1] == c[upos][j] &&
              c[uupos][j - 1] >= c[i][j]) {
            dp[i][j] += dp[i][j - 1];
          }
        }
      }
      ans += dp[i][j];
    }
  }
  printf("%lld", ans);
  return 0;
}
