#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> a;
vector<vector<int> > tl, tr, tu, td;
bool check(char c, int x, int y) {
  if (x < 0 || y < 0) return false;
  if (x >= n || y >= m) return false;
  if (a[x][y] != c) return false;
  return true;
}
void Sol() {
  cin >> n >> m;
  a = vector<string>(n, "");
  for (int i = 0; i < n; i++) cin >> a[i];
  tl = vector<vector<int> >(n, vector<int>(m, 1));
  tr = vector<vector<int> >(n, vector<int>(m, 1));
  tu = vector<vector<int> >(n, vector<int>(m, 1));
  td = vector<vector<int> >(n, vector<int>(m, 1));
  char c;
  for (int i = 0; i < n; i++) {
    c = ' ';
    int count = 0;
    for (int j = 0; j < m; j++) {
      if (a[i][j] != c) {
        count = 1;
        c = a[i][j];
      } else {
        count++;
      }
      tl[i][j] = count;
    }
  }
  for (int i = 0; i < n; i++) {
    c = ' ';
    int count = 0;
    for (int j = m - 1; j >= 0; j--) {
      if (a[i][j] != c) {
        count = 1;
        c = a[i][j];
      } else {
        count++;
      }
      tr[i][j] = min(count, tl[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (check(a[i][j], i - 1, j)) {
        tu[i][j] = min(tu[i - 1][j] + 1, tr[i][j]);
      } else {
        tu[i][j] = 1;
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (check(a[i][j], i + 1, j)) {
        td[i][j] = min(td[i + 1][j] + 1, tu[i][j]);
      } else {
        td[i][j] = 1;
      }
    }
  }
  long long res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) res += td[i][j];
  }
  cout << res;
}
void preprocess() {}
int main() {
  preprocess();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int num_test = 1;
  while (num_test--) {
    Sol();
    if (num_test != 0) cout << endl;
  }
}
