#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5, mod = 1e9 + 9, mod1 = 998244353, mod2 = 1e9 + 9,
          inf = 1e9 + 7;
const long long infll = 1e18 + 7;
int n, m;
long long ans;
char a[N][N];
long long dp[N][N][26];
int lst[N][N];
bool ck(int x1, int _y1_, int x2, int y2, int k) {
  return dp[x2][y2][k] - dp[x2][_y1_ - 1][k] - dp[x1 - 1][y2][k] +
             dp[x1 - 1][_y1_ - 1][k] ==
         (long long)(x2 - x1 + 1) * (long long)(y2 - _y1_ + 1);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      for (int k = 0; k < 26; k++) {
        dp[i][j][k] = dp[i - 1][j][k] + dp[i][j - 1][k] - dp[i - 1][j - 1][k];
      }
      dp[i][j][a[i][j] - 'a']++;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!lst[i][j]) {
        int x = i, y = j;
        while (a[x][y] == a[i][j]) {
          lst[x][y] = x - i + 1;
          x++;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i < lst[i][j] * 3) continue;
      int x1 = i - lst[i][j], x2 = i - lst[i][j] * 2;
      if (a[x1][j] == a[i][j] || a[x2][j] == a[x1][j]) continue;
      if (lst[x1][j] != lst[i][j] || lst[x2][j] < lst[i][j]) continue;
      int l = 1, r = j;
      while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (!ck(i - lst[i][j] + 1, j - mid + 1, i, j, a[i][j] - 'a') ||
            !ck(x1 - lst[i][j] + 1, j - mid + 1, x1, j, a[x1][j] - 'a') ||
            !ck(x2 - lst[i][j] + 1, j - mid + 1, x2, j, a[x2][j] - 'a')) {
          r = mid - 1;
        } else {
          l = mid;
        }
      }
      ans += l;
    }
  }
  cout << ans;
}
