#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long N = 2000 + 10;
const long long IM = 1e15 + 37;
const long double PI = 3.1415926535897932384;
inline void PP(long long n) { cout << n << " "; }
void PV(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void PVV(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << "\n";
}
void PA(long long v[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cout << v[i] << ' ';
  cout << "\n";
}
void IN(long long a[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cin >> a[i];
}
inline void op() {}
long long n, m;
bool ck(long long x, long long y) {
  if (x >= 0 && y >= 0 && x < n && y < m) return 1;
  return 0;
}
void pr(long long a[N][N]) {
  cout << "\n";
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cout << a[i][j] << " ";
    }
    cout << "\n";
  }
  cout << "\n";
}
long long ld[N][N], rd[N][N], dl[N][N], dr[N][N];
signed main() {
  op();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  string s[n];
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      long long x = i - 1, y = j, a = i, b = j - 1;
      if (ck(x, y) && s[x][y] == s[i][j] && ck(a, b) && s[i][j] == s[a][b])
        ld[i][j] = min(ld[x][y], ld[a][b]) + 1;
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = m - 1; j >= 0; j--) {
      long long x = i - 1, y = j, a = i, b = j + 1;
      if (ck(x, y) && s[x][y] == s[i][j] && ck(a, b) && s[i][j] == s[a][b])
        rd[i][j] = min(rd[x][y], rd[a][b]) + 1;
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    for (long long j = 0; j < m; j++) {
      long long x = i + 1, y = j, a = i, b = j - 1;
      if (ck(x, y) && s[x][y] == s[i][j] && ck(a, b) && s[i][j] == s[a][b])
        dl[i][j] = min(dl[x][y], dl[a][b]) + 1;
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    for (long long j = m - 1; j >= 0; j--) {
      long long x = i + 1, y = j, a = i, b = j + 1;
      if (ck(x, y) && s[x][y] == s[i][j] && ck(a, b) && s[i][j] == s[a][b])
        dr[i][j] = min(dr[x][y], dr[a][b]) + 1;
    }
  }
  long long ans = n * m;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      long long d = min({ld[i][j], rd[i][j], dl[i][j], dr[i][j]});
      ans += d;
    }
  }
  cout << (ans) << "\n";
  return 0;
}
