#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
const int MAXN = 2e3 + 10;
int n, m;
int prefgor[MAXN][27];
int prefver[MAXN][27];
char a[MAXN][MAXN];
vector<pair<int, int> > stgor[MAXN][26];
vector<pair<int, int> > stver[MAXN][26];
int dp[MAXN][MAXN];
void calcpref() {
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      for (int c = 0; c < 26; ++c)
        prefgor[i][c] = prefgor[i - 1][c] + (c == a[i][j]);
    }
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i) {
      for (int c = 0; c < 26; ++c)
        prefver[i][c] = prefver[i - 1][c] + (c == a[i][j]);
    }
  }
}
void solve() {
  cin >> n >> m;
  ++n;
  ++m;
  for (int i = 2; i <= n; ++i)
    for (int j = 2; j <= m; ++j) cin >> a[i][j];
  for (int i = 0; i < MAXN; ++i)
    for (int j = 0; j < MAXN; ++j) dp[i][j] = 1;
  long long ans = 0;
  for (int i = 2; i <= n; ++i) {
    for (int j = 2; j <= m; ++j) {
      if (a[i][j] == a[i - 1][j] && a[i][j] == a[i - 1][j - 1] &&
          a[i][j] == a[i - 1][j + 1] && a[i][j] == a[i - 2][j])
        dp[i][j] = min({dp[i - 1][j - 1], dp[i - 1][j + 1], dp[i - 2][j]}) + 1;
      ans += dp[i][j];
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve(), cout << '\n';
  return 0;
}
