#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> field(n + 2, vector<int>(m + 2, -1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char a;
      cin >> a;
      field[i + 1][j + 1] = a - 'a' + 1;
    }
  }
  vector<vector<int>> len(n + 2, vector<int>(m + 2));
  for (int i = 2; i < n; i++) {
    for (int j = 1; j <= m; j++) {
      if (field[i][j] == field[i - 1][j]) {
        continue;
      }
      int e = i;
      while (field[i][j] == field[e][j]) {
        e++;
      }
      len[i][j] = e - i;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int w = 0, lent = 0;
    int c1 = -1, c2 = -1, c3 = -1;
    for (int j = 1; j <= m; j++) {
      if (len[i][j] == 0) {
        w = 0;
        lent = 0;
        c1 = -1;
        c2 = -1;
        c3 = -1;
        continue;
      }
      int e = i - 2;
      while (e >= 0 && field[e][j] == field[e + 1][j]) {
        e--;
      }
      bool up = false, down = false;
      if (i - max(e, 0) - 1 >= len[i][j]) {
        up = true;
      }
      e = i + len[i][j] + 1;
      while (e <= n + 1 && field[e][j] == field[e - 1][j]) {
        e++;
      }
      if (min(n + 1, e) - (i + len[i][j]) >= len[i][j]) {
        down = true;
      }
      if (up && down) {
        if (c1 == field[i - 1][j] && c2 == field[i][j] &&
            c3 == field[i + len[i][j]][j] && len[i][j] == lent) {
          w++;
        } else {
          w = 1;
          lent = len[i][j];
          c1 = field[i - 1][j];
          c2 = field[i][j];
          c3 = field[i + len[i][j]][j];
        }
      } else {
        w = 0;
        lent = 0;
        c1 = -1;
        c2 = -1;
        c3 = -1;
      }
      ans += w;
    }
  }
  cout << ans;
  return 0;
}
