#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 17;
int n, m;
long long p[MAXN][MAXN], d[MAXN][MAXN];
char a[MAXN][MAXN];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  memset(a, '*', sizeof(a));
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= m; i++) d[1][i] = 1;
  for (int i = 2; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == a[i - 1][j])
        d[i][j] = d[i - 1][j] + 1;
      else
        d[i][j] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int t = i - d[i][j];
      if (d[t][j] != d[i][j]) continue;
      t = t - d[t][j];
      if (d[t][j] < d[i][j]) continue;
      p[i][j] = 1;
      if (p[i][j - 1] == 0) continue;
      if (a[i][j - 1] == a[i][j] and d[i][j - 1] == d[i][j] and
          a[i - d[i][j]][j] == a[i - d[i][j]][j - 1] and a[t][j] == a[t][j - 1])
        p[i][j] += p[i][j - 1];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) ans += p[i][j];
  cout << ans;
  return 0;
}
