#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, m;
char g[N][N];
int f[N][N];
int main() {
  cin >> n >> m;
  for (int i = 2; i <= n + 1; i++) {
    scanf("%s", g[i] + 1);
  }
  long long ans = 0;
  for (int i = 2; i <= n + 1; i++) {
    for (int j = 1; j <= m; j++) {
      if (g[i - 1][j - 1] != g[i][j] || g[i - 1][j] != g[i][j] ||
          g[i - 1][j + 1] != g[i][j] || g[i - 2][j] != g[i][j])
        f[i][j] = 1;
      else
        f[i][j] = 1 + min(min(f[i - 1][j - 1], f[i - 1][j + 1]), f[i - 2][j]);
      ans += f[i][j];
    }
  }
  cout << ans << endl;
  return 0;
}
