#include <bits/stdc++.h>
short int Size[1000][1000];
int main() {
  short int n, m;
  scanf("%hi%hi", &n, &m);
  char C[1000][1000];
  for (short int i = 0; i < n; i++) {
    scanf("\n");
    for (short int j = 0; j < m; j++) scanf("%c", &C[i][j]);
  }
  for (short int i = 0; i < n - 2; i++)
    for (short int j = 0; j < m; j++) {
      short int lineSize = i + 1;
      while (lineSize < n && C[i][j] == C[lineSize][j]) lineSize++;
      lineSize -= i;
      if (i + 3 * lineSize > n) continue;
      bool b = false;
      for (short int ind = i + lineSize + 1; ind < i + 2 * lineSize; ind++)
        if (C[i + lineSize][j] != C[ind][j]) {
          b = true;
          break;
        }
      if (b || C[i + lineSize][j] == C[i + 2 * lineSize][j]) continue;
      for (short int ind = i + 2 * lineSize + 1; ind < i + 3 * lineSize; ind++)
        if (C[i + 2 * lineSize][j] != C[ind][j]) {
          b = true;
          break;
        }
      if (b) continue;
      Size[i][j] = lineSize;
    }
  long long ans = 0;
  short int loc = 0;
  for (short int i = 0; i < n - 2; i++)
    for (short int j = 0; j < m; j++) {
      if (!j) {
        ans += (loc + 1) * 1ll * loc / 2ll;
        loc = 1;
        if (!Size[i][j]) loc = 0;
        continue;
      }
      if (Size[i][j - 1] == Size[i][j] && C[i][j] == C[i][j - 1] &&
          C[i + Size[i][j]][j] == C[i + Size[i][j]][j - 1] &&
          C[i + 2 * Size[i][j]][j] == C[i + 2 * Size[i][j]][j - 1])
        loc++;
      else {
        ans += (loc + 1) * 1ll * loc / 2ll;
        loc = 1;
      }
      if (!Size[i][j]) loc = 0;
    }
  ans += (loc + 1) * 1ll * loc / 2ll;
  printf("%lli", ans);
}
