#include <bits/stdc++.h>
using namespace std;
int n, m, c[1050][1050], ans;
char a[1050][1050];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = m; j; j--)
      if (a[i][j] == a[i][j + 1])
        c[i][j] = c[i][j + 1] + 1;
      else
        c[i][j] = 1;
  for (int j = 1; j <= m; j++)
    for (int i = 1; i <= n; i++) {
      int s[3] = {}, r = 0;
      int k = i, mi = 1e9;
      while (k <= n) {
        s[r]++;
        mi = min(mi, c[k][j]);
        if (r == 2 && s[r] == s[r - 1]) {
          ans += mi;
          break;
        }
        k++;
        if (a[k][j] != a[k - 1][j]) r++;
        if (r && s[r] > s[r - 1]) break;
        if (r == 2 && s[0] != s[1]) break;
        if (r == 3) break;
      }
    }
  printf("%d\n", ans);
}
