#include <bits/stdc++.h>
using namespace std;
int y, x;
int cords(int xc, int yc) { return xc + yc * x; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> y >> x;
  int* colors = new int[x * y]();
  pair<int, int>* dots = new pair<int, int>[x * y]();
  int* matchingsUpwards = new int[x * y]();
  string str;
  for (int i = 0; i < y; i++) {
    cin >> str;
    for (int j = 0; j < x; j++) {
      colors[cords(j, i)] = str[j];
      dots[cords(j, i)] = {0, 0};
      matchingsUpwards[cords(j, i)] = 0;
    }
  }
  for (int i = 0; i < x; i++) {
    int match = 0;
    int current = 0;
    int oneAbove = -1;
    int twoAbove = -1;
    int prevChar = -1;
    for (int j = 0; j < y; j++) {
      if (i != x - 1) {
        if (colors[cords(i, j)] == colors[cords(i + 1, j)])
          match++;
        else
          match = 0;
        matchingsUpwards[cords(i, j)] = match;
      }
      if (prevChar == colors[cords(i, j)]) {
        current++;
      } else {
        twoAbove = oneAbove;
        oneAbove = current;
        current = 1;
      }
      if (current == oneAbove && twoAbove >= oneAbove) {
        dots[cords(i, j)] = {current * 3, 1};
      }
      prevChar = colors[cords(i, j)];
    }
  }
  long long answer = 0;
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      if (dots[cords(i, j)].first != 0) {
        for (int k = i + 1; k < x; k++) {
          if (matchingsUpwards[cords(k - 1, j)] >= dots[cords(i, j)].first) {
            dots[cords(k, j)] = {0, 0};
            dots[cords(i, j)].second++;
          } else {
            break;
          }
        }
        long long n = dots[cords(i, j)].second;
        answer += ((n * n + n) / 2);
      }
    }
  }
  cout << answer << '\n';
}
