#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
bool compare(const pair<int long long, int long long> &a,
             const pair<int long long, int long long> &b) {
  return a.second <= b.second;
}
int long long inline power(int long long a, int long long b, int long long p) {
  a %= p;
  int long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return ans;
}
int long long inv(int long long n, int long long p) {
  return power(n, p - 2, p);
}
bool inline isPrime(int long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int long long gcd(int long long a, int long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void solve() {
  int long long n, m, i, j, k, l, r;
  cin >> n >> m;
  vector<string> s(n);
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  vector<vector<int long long> > dp(n, vector<int long long>(m, 0));
  int long long ans = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (i >= 2 && j >= 1 && j + 1 < m && s[i][j] == s[i - 1][j] &&
          s[i][j] == s[i - 1][j - 1] && s[i][j] == s[i - 2][j] &&
          s[i][j] == s[i - 1][j + 1]) {
        dp[i][j] = min(dp[i - 1][j], min(dp[i - 1][j - 1],
                                         min(dp[i - 2][j], dp[i - 1][j + 1]))) +
                   1;
      } else
        dp[i][j] = 1;
      ans += dp[i][j];
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int long long t = 1;
  while (t--) solve();
}
