#include <bits/stdc++.h>
using namespace std;
int Up[1011][1011], Down[1011][1011];
int n, m, i, j, k;
char s[1011][1011];
long long res = 0;
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> s[i][j];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      Up[i][j] = 1;
      if (s[i][j] == s[i - 1][j]) Up[i][j] += Up[i - 1][j];
    }
  for (i = n; i >= 1; i--)
    for (j = 1; j <= m; j++) {
      Down[i][j] = 1;
      if (s[i + 1][j] == s[i][j]) Down[i][j] += Down[i + 1][j];
    }
  for (i = 2; i <= n; i++)
    for (j = 1; j <= m; j++) {
      if (Up[i][j] == 1) {
        int H = Up[i][j] + Down[i][j] - 1;
        int uu = i - 1;
        int dd = i + Down[i][j];
        if (Up[uu][j] >= H && Down[dd][j] >= H) {
          int c = 1;
          res++;
          for (k = j + 1;; k++) {
            c++;
            if ((s[i][k] == s[i][j]) && (s[uu][k] == s[uu][j]) &&
                (s[dd][k] == s[dd][j]) && (Up[uu][k] >= H) &&
                (Down[dd][k] >= H) && (Up[i][k]) && (Up[i][j]) &&
                (Down[i][k] == Down[i][j]))
              res += c;
            else
              break;
          }
          j = k - 1;
        }
      }
    }
  cout << res << endl;
  return 0;
}
