#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535898;
const long long INF = LLONG_MAX;
const long long MOD = 1000000007;
int dp[2005][2005][4];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  char a[n + 1][m + 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 0; i <= n + 1; i++)
    for (int j = 0; j <= m + 1; j++)
      for (int k = 0; k < 4; k++) dp[i][j][k] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j == 1)
        dp[i][j][0] = 1;
      else if (a[i][j] == a[i][j - 1])
        dp[i][j][0] = dp[i][j - 1][0] + 1;
      else
        dp[i][j][0] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      if (j == m)
        dp[i][j][1] = 1;
      else if (a[i][j] == a[i][j + 1])
        dp[i][j][1] = dp[i][j + 1][1] + 1;
      else
        dp[i][j][1] = 1;
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      if (i == 1)
        dp[i][j][2] = 1;
      else if (a[i][j] == a[i - 1][j])
        dp[i][j][2] = dp[i - 1][j][2] + 1;
      else
        dp[i][j][2] = 1;
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = n; i >= 1; i--) {
      if (i == n)
        dp[i][j][3] = 1;
      else if (a[i][j] == a[i + 1][j])
        dp[i][j][3] = dp[i + 1][j][3] + 1;
      else
        dp[i][j][3] = 1;
    }
  }
  int v1[n + 2][m + 2], v[n + 2][m + 2], h1[n + 2][m + 2], h[n + 2][m + 2];
  for (int i = 0; i <= n + 1; i++)
    for (int j = 0; j <= m + 1; j++)
      v1[i][j] = 0, v[i][j] = 0, h[i][j] = 0, h1[i][j] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      v[i][j] = min(min(dp[i][j][2], dp[i][j][3]), v[i][j - 1] + 1);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      v1[i][j] = min(min(dp[i][j][2], dp[i][j][3]), v1[i][j + 1] + 1);
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      h[i][j] = min(min(dp[i][j][0], dp[i][j][1]), h[i - 1][j] + 1);
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = n; i >= 1; i--) {
      h1[i][j] = min(min(dp[i][j][0], dp[i][j][1]), h1[i + 1][j] + 1);
    }
  }
  long long f = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int ma = min(min(h[i][j], h1[i][j]), min(v[i][j], v1[i][j]));
      f += ma;
    }
  }
  cout << f << "\n";
}
