#include <bits/stdc++.h>
using namespace std;
const double P = 3.141592653589793;
int n, m;
string s[2000];
int tl[2000][2000], tr[2000][2000], dl[2000][2000], dr[2000][2000];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      tl[i][j] = tr[i][j] = dl[i][j] = dr[i][j] = 1;
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (s[i][j] == s[i - 1][j] and s[i][j] == s[i][j - 1]) {
        tl[i][j] = min(tl[i - 1][j], tl[i][j - 1]) + 1;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = m - 2; j >= 0; j--) {
      if (s[i][j] == s[i - 1][j] and s[i][j] == s[i][j + 1]) {
        tr[i][j] = min(tr[i - 1][j], tr[i][j + 1]) + 1;
      }
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 1; j < m; j++) {
      if (s[i][j] == s[i + 1][j] and s[i][j] == s[i][j - 1]) {
        dl[i][j] = min(dl[i + 1][j], dl[i][j - 1]) + 1;
      }
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = m - 2; j >= 0; j--) {
      if (s[i][j] == s[i + 1][j] and s[i][j] == s[i][j + 1]) {
        dr[i][j] = min(dr[i + 1][j], dr[i][j + 1]) + 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans += min({tl[i][j], tr[i][j], dl[i][j], dr[i][j]});
    }
  }
  cout << ans << endl;
  return 0;
}
