#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2000;
int cnt_up[MAX_N][MAX_N], cnt_down[MAX_N][MAX_N], left_part[MAX_N][MAX_N],
    right_part[MAX_N][MAX_N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  for (auto& e : a) cin >> e;
  for (int i = 0; i < m; ++i) cnt_up[0][i] = 1;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i - 1][j] == a[i][j])
        cnt_up[i][j] = cnt_up[i - 1][j] + 1;
      else
        cnt_up[i][j] = 1;
    }
  }
  for (int i = 0; i < m; ++i) cnt_down[n - 1][i] = 1;
  for (int i = n - 2; i >= 0; --i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == a[i + 1][j])
        cnt_down[i][j] = cnt_down[i + 1][j] + 1;
      else
        cnt_down[i][j] = 1;
    }
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      left_part[i][j] = 1;
      right_part[i][j] = 1;
    }
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      if (a[i][j] != a[i][j - 1]) continue;
      left_part[i][j] =
          min({left_part[i][j - 1] + 1, cnt_up[i][j], cnt_down[i][j]});
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = m - 2; j >= 0; --j) {
      if (a[i][j] != a[i][j + 1]) continue;
      right_part[i][j] =
          min({right_part[i][j + 1] + 1, cnt_up[i][j], cnt_down[i][j]});
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) ans += min(left_part[i][j], right_part[i][j]);
  cout << ans;
  return 0;
}
