#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e3 + 5;
long long len[MAXN][MAXN], temp[MAXN][MAXN], cnt[MAXN][MAXN];
signed main() {
  memset(len, 0, sizeof(len));
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, m;
  cin >> n >> m;
  string grid[n];
  for (long long i = 0; i < n; i++) cin >> grid[i];
  for (long long i = 0; i < m; i++) {
    temp[0][i] = 1;
    for (long long j = 1; j < n; j++) {
      temp[j][i] = 1;
      if (grid[j][i] == grid[j - 1][i]) temp[j][i] += temp[j - 1][i];
      bool f = true;
      if (j + 1 < 3 * temp[j][i]) continue;
      if (temp[j][i] != temp[j - temp[j][i]][i]) continue;
      if (temp[j][i] > temp[j - 2 * temp[j][i]][i]) continue;
      if (f and (grid[j][i] == grid[j - temp[j][i]][i] or
                 grid[j - temp[j][i]][i] == grid[j - 2 * temp[j][i]][i])) {
        f = false;
      }
      if (f) {
        len[j][i] = temp[j][i];
      }
    }
  }
  memset(cnt, 0, sizeof(cnt));
  for (long long i = 0; i < n; i++) {
    cnt[i][0] = (len[i][0] > 0);
  }
  for (long long i = 1; i < m; i++) {
    for (long long j = 2; j < n; j++) {
      if (len[j][i] == 0) continue;
      cnt[j][i] = 1;
      if (len[j][i - 1] != len[j][i]) continue;
      bool f = true;
      for (long long k = 0; k < 3 * len[j][i]; k++) {
        if (grid[j - k][i] != grid[j - k][i - 1]) {
          f = false;
          break;
        }
      }
      if (f) cnt[j][i] += cnt[j][i - 1];
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      ans += cnt[i][j];
    }
  }
  cout << ans << "\n";
  return 0;
}
