#include <bits/stdc++.h>
using namespace std;
const int M = 2e3 + 10;
char a[M][M];
int dp[M][M], n, m;
int main() {
  scanf("%d%d", &n, &m);
  long long ans = 0LL;
  for (int i = 2; i <= n + 1; i++) scanf("%s", a[i] + 1);
  for (int i = 2; i <= n + 1; i++)
    for (int j = 1; j <= m; j++) {
      if ((a[i][j] == a[i - 1][j]) && (a[i][j] == a[i - 1][j - 1]) &&
          (a[i][j] == a[i - 1][j + 1]) && (a[i][j] == a[i - 2][j]))
        dp[i][j] =
            1 + min(min(dp[i - 1][j - 1], dp[i - 1][j + 1]), dp[i - 2][j]);
      else
        dp[i][j] = 1;
      ans = ans + dp[i][j];
    }
  printf("%lld\n", ans);
  return 0;
}
