#include <bits/stdc++.h>
char mp[2005][2005];
int hang[2005][2005];
int hang2[2005][2005];
int lie[2005][2005];
int lie2[2005][2005];
using namespace std;
int main() {
  int i, j, n, m, t;
  memset(mp, 0, sizeof(mp));
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    for (j = m; j >= 1; j--) {
      if (mp[i - 1][j] != mp[i][j] || mp[i][j + 1] != mp[i][j])
        hang[i][j] = 1;
      else
        hang[i][j] = min(hang[i - 1][j], hang[i][j + 1]) + 1;
    }
    for (j = 1; j <= m; j++) {
      if (mp[i - 1][j] != mp[i][j] || mp[i][j - 1] != mp[i][j])
        hang2[i][j] = 1;
      else
        hang2[i][j] = min(hang2[i - 1][j], hang2[i][j - 1]) + 1;
    }
  }
  for (i = n; i >= 1; i--) {
    for (j = 1; j <= m; j++) {
      if (mp[i + 1][j] != mp[i][j] || mp[i][j - 1] != mp[i][j])
        lie[i][j] = 1;
      else
        lie[i][j] = min(lie[i + 1][j], lie[i][j - 1]) + 1;
    }
    for (j = m; j >= 1; j--) {
      if (mp[i + 1][j] != mp[i][j] || mp[i][j + 1] != mp[i][j])
        lie2[i][j] = 1;
      else
        lie2[i][j] = min(lie2[i + 1][j], lie2[i][j + 1]) + 1;
    }
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      ans += min(min(hang[i][j], hang2[i][j]), min(lie[i][j], lie2[i][j]));
    }
  cout << ans << endl;
  return 0;
}
