#include <bits/stdc++.h>
using namespace std;
mt19937 gen(time(0));
int const inf = 1e9 + 10;
long long const INF = 1e18;
int mod = 998244353;
long long ans = 0;
struct pole {
  int h, c1, c2, c3, l;
};
int n, m;
pole mas[1100][1100];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char first;
      cin >> first;
      mas[i][j].c2 = int(first);
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 1; i < n - 1; i++) {
      if (mas[i][j].c2 != mas[i - 1][j].c2) {
        int i1 = i - 1;
        int kol1 = 1;
        while (i1 > 0 && mas[i1][j].c2 == mas[i1 - 1][j].c2) {
          i1--;
          kol1++;
        }
        int i2 = i;
        int kol2 = 1;
        while (i2 < n - 1 && mas[i2][j].c2 == mas[i2 + 1][j].c2) {
          i2++;
          kol2++;
        }
        if (i2 == n - 1) continue;
        int i3 = i2 + 1;
        int kol3 = 1;
        while (i3 < n - 1 && mas[i3][j].c2 == mas[i3 + 1][j].c2) {
          i3++;
          kol3++;
        }
        if (kol1 < kol2 || kol3 < kol2) continue;
        ans++;
        mas[i][j].h = kol2;
        mas[i][j].c1 = mas[i1][j].c2;
        mas[i][j].c3 = mas[i3][j].c2;
        mas[i][j].l = 1;
        if (j == 0) continue;
        if (mas[i][j - 1].c1 == mas[i][j].c1 &&
            mas[i][j - 1].c2 == mas[i][j].c2 &&
            mas[i][j - 1].c3 == mas[i][j].c3 &&
            mas[i][j - 1].h == mas[i][j].h) {
          ans += mas[i][j - 1].l;
          mas[i][j].l += mas[i][j - 1].l;
        }
      }
    }
  }
  cout << ans;
  return 0;
}
