#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
char g1[N][N];
int dp1[N][N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  int n = 0, m = 0, ans1 = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> g1[i];
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      dp1[i][j] = 1;
      if (i > 2 && j > 0 && j < m - 1 && g1[i][j] == g1[i - 1][j] &&
          g1[i][j] == g1[i - 2][j] && g1[i][j] == g1[i - 1][j - 1] &&
          g1[i][j] == g1[i - 1][j + 1]) {
        dp1[i][j] +=
            min(min(dp1[i - 1][j - 1], dp1[i - 1][j + 1]), dp1[i - 2][j]);
      }
      ans1 += dp1[i][j];
    }
  }
  cout << ans1 << endl;
  return 0;
}
