#include <bits/stdc++.h>
using namespace std;
int const N = 1e3 + 9;
int com[N][N], comh[N][N];
int n, m;
char arr[N][N];
inline void makeCom() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] == arr[i][j - 1])
        com[i][j] = com[i][j - 1] + 1;
      else
        com[i][j] = 1;
    }
  }
}
inline void makeComh() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] == arr[i - 1][j])
        comh[i][j] = comh[i - 1][j] + 1;
      else
        comh[i][j] = 1;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", arr[i] + 1);
  }
  makeCom();
  makeComh();
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int last = comh[i][j];
      if (3 * last > i) continue;
      int mid = comh[i - last][j];
      if (last != mid) continue;
      int first = comh[i - mid - last][j];
      if (first < mid) continue;
      int mn = 1e9;
      for (int k = 0; k < 3 * last; k++) {
        mn = min(mn, com[i - k][j]);
      }
      ans += mn;
    }
  }
  printf("%lld", ans);
  return 0;
}
