#include <bits/stdc++.h>
using namespace std;
int MIN(int a, int b, int c, int d) { return min(min(a, b), min(c, d)); }
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  vector<vector<int>> ul(n, vector<int>(m)), ur(n, vector<int>(m)),
      dl(n, vector<int>(m)), dr(n, vector<int>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (i == 0 || j == 0 || v[i - 1][j] != v[i][j] || v[i][j - 1] != v[i][j])
        ul[i][j] = 1;
      else
        ul[i][j] = min(ul[i - 1][j], ul[i][j - 1]) + 1;
  for (int i = 0; i < n; i++)
    for (int j = m - 1; ~j; j--)
      if (i == 0 || j == m - 1 || v[i - 1][j] != v[i][j] ||
          v[i][j + 1] != v[i][j])
        ur[i][j] = 1;
      else
        ur[i][j] = min(ur[i - 1][j], ur[i][j + 1]) + 1;
  for (int i = n - 1; ~i; i--)
    for (int j = 0; j < m; j++)
      if (i == n - 1 || j == 0 || v[i + 1][j] != v[i][j] ||
          v[i][j - 1] != v[i][j])
        dl[i][j] = 1;
      else
        dl[i][j] = min(dl[i + 1][j], dl[i][j - 1]) + 1;
  for (int i = n - 1; ~i; i--)
    for (int j = m - 1; ~j; j--)
      if (i == n - 1 || j == m - 1 || v[i + 1][j] != v[i][j] ||
          v[i][j + 1] != v[i][j])
        dr[i][j] = 1;
      else
        dr[i][j] = min(dr[i + 1][j], dr[i][j + 1]) + 1;
  long long ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      ans += MIN(ul[i][j], ur[i][j], dl[i][j], dr[i][j]);
  cout << ans << '\n';
  return 0;
}
