#include <bits/stdc++.h>
using namespace std;
const long long int inf = (long long int)1e18 + 19;
const long long int mod = (long long int)1e9 + 7;
long long int up[1001][1001], lft[1001][1001];
void cazz() {
  long long int t = 1, i = 0, j, n;
  while (t--) {
    long long int m;
    cin >> n >> m;
    char s[n][m];
    for (long long int i = 0; i < n; i++)
      for (long long int j = 0; j < m; j++) cin >> s[i][j];
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 1; j < m; j++) {
        if (s[i][j] == s[i][j - 1]) lft[i][j] += 1 + lft[i][j - 1];
      }
    }
    for (long long int i = 0; i < m; i++) {
      for (long long int j = 1; j < n; j++) {
        if (s[j][i] == s[j - 1][i]) up[j][i] += 1 + up[j - 1][i];
      }
    }
    long long int ans = 0;
    for (long long int i = 2; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        long long int val1 = lft[i][j] + 1;
        long long int val2 = up[i][j] + 1;
        if (i - (3 * val2) + 1 < 0) continue;
        if (up[i - val2][j] == up[i][j] && up[i - val2 - val2][j] >= up[i][j]) {
          ans += 1;
          long long int mn = inf;
          long long int k;
          bool f = 0;
          for (long long int k = i - (3 * val2) + 1; k < i + 1; k++)
            mn = min(mn, lft[k][j]), f = 1;
          if (f) ans += mn;
        }
      }
    }
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cazz();
  return 0;
}
