#include <bits/stdc++.h>
using namespace std;
template <typename T>
void input(vector<T> &arr, long long int n) {
  T temp;
  for (long long int i = 0; i < n; i++) cin >> temp, arr.push_back(temp);
}
template <typename T>
void output(vector<T> arr) {
  for (auto x : arr) cout << x << " ";
  cout << endl;
}
template <typename T>
void input_set(set<T> &arr, long long int n) {
  T temp;
  for (long long int i = 0; i < n; i++) cin >> temp, arr.insert(temp);
}
long long int mul(long long int a, long long int b) {
  return (a % 1000000007 * b % 1000000007) % 1000000007;
}
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b > 0) {
    if (b & 1) ans = mul(ans, a);
    a = mul(a, a);
    ;
    b >>= 1;
  }
  return ans;
}
int right_up[2002][2002];
int left_up[2002][2002];
int right_down[2002][2002];
int left_down[2002][2002];
char mat[2002][2002];
void solve() {
  memset(right_up, 0, sizeof(right_up));
  memset(left_up, 0, sizeof(left_up));
  memset(right_down, 0, sizeof(right_down));
  memset(left_down, 0, sizeof(left_down));
  memset(mat, 'Q', sizeof(mat));
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> mat[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int l = 1, u = 1, c = 2;
      if (mat[i][j - 1] == mat[i][j]) l = left_up[i][j - 1] + 1;
      if (mat[i - 1][j] == mat[i][j]) u = left_up[i - 1][j] + 1;
      if (mat[i - 1][j - 1] == mat[i][j]) c = left_up[i - 1][j - 1] + 2;
      left_up[i][j] = min(l, u);
      left_up[i][j] = min(left_up[i][j], c);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      int l = 1, u = 1, c = 2;
      if (mat[i][j + 1] == mat[i][j]) l = right_up[i][j + 1] + 1;
      if (mat[i - 1][j] == mat[i][j]) u = right_up[i - 1][j] + 1;
      if (mat[i - 1][j + 1] == mat[i][j]) c = right_up[i - 1][j + 1] + 2;
      right_up[i][j] = min(l, u);
      right_up[i][j] = min(right_up[i][j], c);
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      int l = 1, u = 1, c = 2;
      if (mat[i][j - 1] == mat[i][j]) l = left_down[i][j - 1] + 1;
      if (mat[i + 1][j] == mat[i][j]) u = left_down[i + 1][j] + 1;
      if (mat[i + 1][j - 1] == mat[i][j]) c = left_down[i + 1][j - 1] + 2;
      left_down[i][j] = min(l, u);
      left_down[i][j] = min(left_down[i][j], c);
    }
  }
  long long int ans = 0;
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      int l = 1, u = 1, c = 2;
      if (mat[i][j + 1] == mat[i][j]) l = right_down[i][j + 1] + 1;
      if (mat[i + 1][j] == mat[i][j]) u = right_down[i + 1][j] + 1;
      if (mat[i + 1][j + 1] == mat[i][j]) c = right_down[i + 1][j + 1] + 2;
      right_down[i][j] = min(l, u);
      right_down[i][j] = min(right_down[i][j], c);
      int curans = 1e8;
      curans = min(curans, left_down[i][j]);
      curans = min(curans, right_up[i][j]);
      curans = min(curans, left_up[i][j]);
      curans = min(curans, right_down[i][j]);
      ans += curans;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int testcases = 1;
  while (testcases--) {
    solve();
  }
}
