#include <bits/stdc++.h>
using namespace std;
char a[2005][2005];
long long int upl[2005][2005];
long long int upr[2005][2005];
long long int dnl[2005][2005];
long long int dnr[2005][2005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      if (i - 1 >= 1 && j - 1 >= 1 && a[i][j] == a[i - 1][j] &&
          a[i][j] == a[i][j - 1]) {
        upl[i][j] = 1 + min(upl[i - 1][j], upl[i][j - 1]);
      } else {
        upl[i][j] = 1;
      }
    }
  }
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = m; j >= 1; j--) {
      if (i - 1 >= 1 && j + 1 <= m && a[i][j] == a[i - 1][j] &&
          a[i][j] == a[i][j + 1]) {
        upr[i][j] = 1 + min(upr[i - 1][j], upr[i][j + 1]);
      } else {
        upr[i][j] = 1;
      }
    }
  }
  for (long long int i = n; i >= 1; i--) {
    for (long long int j = 1; j <= m; j++) {
      if (i + 1 <= n && j >= 2 && a[i][j] == a[i + 1][j] &&
          a[i][j] == a[i][j - 1]) {
        dnl[i][j] = 1 + min(dnl[i + 1][j], dnl[i][j - 1]);
      } else {
        dnl[i][j] = 1;
      }
    }
  }
  for (long long int i = n; i >= 1; i--) {
    for (long long int j = m; j >= 1; j--) {
      if (i + 1 <= n && j + 1 <= m && a[i][j] == a[i + 1][j] &&
          a[i][j] == a[i][j + 1]) {
        dnr[i][j] = 1 + min(dnr[i + 1][j], dnr[i][j + 1]);
      } else {
        dnr[i][j] = 1;
      }
    }
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 1; j <= m; j++) {
      ans += min(min(upl[i][j], upr[i][j]), min(dnl[i][j], dnr[i][j]));
    }
  }
  cout << ans << "\n";
}
