#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int minnm = min(n, m);
  vector<vector<char>> A(n, vector<char>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> A[i][j];
    }
  }
  if (minnm <= 2) {
    cout << n * m << endl;
    return 0;
  }
  vector<vector<int>> UL(n, vector<int>(m, 1));
  for (int i = 2; i < n; ++i) {
    for (int j = 1; j < m - 1; ++j) {
      if (A[i][j] == A[i - 1][j] && A[i][j] == A[i - 2][j] &&
          A[i][j] == A[i - 1][j - 1] && A[i][j] == A[i - 1][j + 1])
        UL[i][j] =
            1 + min(min(UL[i - 1][j - 1], UL[i - 1][j + 1]), UL[i - 2][j]);
    }
  }
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      sum += UL[i][j];
    }
  }
  cout << sum << endl;
  return 0;
}
