#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int N = 1011;
int n, m;
char s[N][N];
int Right[N][N], Down[N][N], Flag[N][N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    Right[i][m] = 1;
    for (int j = m - 1; j >= 1; j--) {
      if (s[i][j] == s[i][j + 1])
        Right[i][j] = Right[i][j + 1] + 1;
      else
        Right[i][j] = 1;
    }
  }
  for (int j = 1; j <= m; j++) {
    Down[n][j] = 1;
    Flag[n][j] = Right[n][j];
    for (int i = n - 1; i >= 1; i--) {
      if (s[i][j] == s[i + 1][j]) {
        Down[i][j] = Down[i + 1][j] + 1;
        Flag[i][j] = min(Right[i][j], Flag[i + 1][j]);
      } else {
        Down[i][j] = 1;
        Flag[i][j] = Right[i][j];
      }
    }
  }
  int ans = 0;
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (m); j++) {
      int height = Down[i][j];
      int si = i + height, ti = i + height + height;
      if (ti > n) continue;
      if (Down[si][j] != height || Down[ti][j] < height) continue;
      int tmp = min(Flag[i][j], Flag[si][j]);
      for (int k = (ti); k <= (ti + height - 1); k++)
        tmp = min(tmp, Right[k][j]);
      ans += tmp;
    }
  cout << ans << endl;
  return 0;
}
