#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; i++) {
    s[i].reserve(m);
    cin >> s[i];
  }
  bool isGood[n][m];
  char colour[n][m][3];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      isGood[i][j] = false;
    }
  }
  for (int i = 0; i < m; i++) {
    int currLen = 1;
    int pLen = -1;
    int ppLen = -1;
    char currCol = s[0][i];
    char pCol;
    char ppCol;
    for (int j = 1; j < n; j++) {
      if (currCol == s[j][i]) {
        currLen += 1;
      } else {
        ppLen = pLen;
        pLen = currLen;
        currLen = 1;
        ppCol = pCol;
        pCol = currCol;
        currCol = s[j][i];
      }
      if (pLen > -1 && currLen >= pLen && ppLen >= pLen) {
        isGood[j - currLen + 1 - 2 * pLen][i] = true;
        colour[j - currLen + 1 - 2 * pLen][i][0] = ppCol;
        colour[j - currLen + 1 - 2 * pLen][i][1] = pCol;
        colour[j - currLen + 1 - 2 * pLen][i][2] = currCol;
      }
    }
  }
  long long res = 0;
  for (int i = 0; i < n; i++) {
    int counter = 0;
    while (counter < m) {
      if (isGood[i][counter]) {
        int count = 1;
        while (true) {
          if (counter + 1 == m) {
            break;
          }
          if (isGood[i][counter + 1] &&
              colour[i][counter][0] == colour[i][counter + 1][0] &&
              colour[i][counter][1] == colour[i][counter + 1][1] &&
              colour[i][counter][2] == colour[i][counter + 1][2]) {
            count++;
            counter++;
          } else {
            break;
          }
        }
        res += count * (count + 1) / 2;
      }
      counter++;
    }
  }
  cout << res;
}
