#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, u[1010][1010], d[1010][1010], l[1010][1010], r[1010][1010], h,
    upi, downi, k;
long long ans;
char c[1010][1010];
int height(int i, int j) { return d[i][j] - u[i][j] + 1; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> c[i][j];
      if (i == 0)
        u[i][j] = i;
      else if (c[i][j] == c[i - 1][j])
        u[i][j] = u[i - 1][j];
      else
        u[i][j] = i;
      if (j == 0)
        l[i][j] = j;
      else if (c[i][j] == c[i][j - 1])
        l[i][j] = l[i][j - 1];
      else
        l[i][j] = j;
    }
  }
  for (i = n - 1; i >= 0; i--) {
    for (j = m - 1; j >= 0; j--) {
      if (i == n - 1)
        d[i][j] = i;
      else if (c[i][j] == c[i + 1][j])
        d[i][j] = d[i + 1][j];
      else
        d[i][j] = i;
      if (j == m - 1)
        r[i][j] = j;
      else if (c[i][j] == c[i][j + 1])
        r[i][j] = r[i][j + 1];
      else
        r[i][j] = j;
    }
  }
  for (i = 1; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (u[i][j] == 0 || d[i][j] == n - 1 || u[i][j] != i) continue;
      h = height(i, j);
      upi = u[i][j] - 1;
      downi = d[i][j] + 1;
      if (height(upi, j) < h || height(downi, j) < h) continue;
      k = j;
      while (u[i][k] == u[i][j] && d[i][k] == d[i][j] &&
             height(u[i][k] - 1, k) >= h && height(d[i][k] + 1, k) >= h &&
             c[i][j] == c[i][k] && c[upi][j] == c[u[i][k] - 1][k] &&
             c[downi][j] == c[d[i][k] + 1][k])
        k++;
      k -= j;
      ans += 1LL * k * (k + 1) / 2;
      j += k - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
