#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  cin >> x;
}
template <typename T, typename T0>
void read(T &x, T0 &y) {
  cin >> x >> y;
}
template <typename T, typename T0, typename T1>
void read(T &x, T0 &y, T1 &z) {
  cin >> x >> y >> z;
}
template <typename T, typename T0, typename T1, typename T2>
void read(T &x, T0 &y, T1 &z, T2 &w) {
  cin >> x >> y >> z >> w;
}
template <typename T, typename T0>
void read(pair<T, T0> &p) {
  cin >> p.first >> p.second;
}
template <typename T>
void read(vector<T> &oneD, long long int n) {
  for (long long int(i) = 0; (i) < (n); ++(i)) {
    long long int x;
    read(x);
    oneD.push_back(x);
  }
}
template <typename T>
void read(T oneD[], long long int n) {
  for (long long int i = 0; i < n; i++) {
    read(oneD[i]);
  }
}
template <typename T>
void write(T &x) {
  cout << x << " ";
}
template <typename T>
void wrtline(T &x) {
  cout << x << "\n";
}
template <typename T, typename T0>
void write(T &x, T0 &y) {
  cout << x << " " << y << "\n";
}
template <typename T, typename T0, typename T1>
void write(T &x, T0 &y, T1 &z) {
  cout << x << " " << y << " " << z << "\n";
}
template <typename T, typename T0, typename T1, typename T2>
void write(T &x, T0 &y, T1 &z, T2 &w) {
  cout << x << " " << y << " " << z << " " << w << "\n";
}
template <typename T, typename T0>
void write(pair<T, T0> &p) {
  write(p.first);
  write(p.second);
  cout << "\n";
}
template <typename T>
void write(vector<T> &oneD, long long int n) {
  for (long long int i = 0; i < n; i++) {
    cout << oneD[i] << " ";
  }
  cout << "\n";
}
template <typename T>
void write(T oneD[], int n) {
  for (long long int i = 0; i < n; i++) {
    write(oneD[i]);
  }
  cout << "\n";
}
template <typename T, typename T0>
void write(map<T, T0> &mpp) {
  for (auto it : mpp) {
    write(it.first);
    cout << ": ";
    write(it.second);
    cout << "\n";
  }
  cout << "\n";
}
void write(vector<vector<long long int>> rc, long long int n, long long int m) {
  for (long long int(i) = 0; (i) < (n); ++(i)) {
    for (long long int(j) = 0; (j) < (m); ++(j)) {
      cout << rc[i][j] << " ";
    }
    cout << "\n";
  }
}
long long int maxl(long long int a, long long int b) { return (a > b) ? a : b; }
long long int minl(long long int a, long long int b) { return (a < b) ? a : b; }
vector<vector<long long int>> ul(2005, vector<long long int>(2005, 1)),
    ur(2005, vector<long long int>(2005, 1)),
    lol(2005, vector<long long int>(2005, 1)),
    lor(2005, vector<long long int>(2005, 1));
long long int n, m;
void solve() {
  read(n, m);
  vector<string> s;
  for (long long int(i) = 0; (i) < (n); ++(i)) {
    string t;
    read(t);
    s.push_back(t);
  }
  for (long long int(i) = 1; (i) <= (n - 1); (i) += (1)) {
    for (long long int(j) = 1; (j) <= (m - 1); (j) += (1)) {
      if (s[i][j] == s[i - 1][j] and s[i][j] == s[i][j - 1])
        ul[i][j] = minl(ul[i - 1][j], ul[i][j - 1]) + 1;
    }
  }
  for (long long int i = n - 2; i >= 0; i--) {
    for (long long int(j) = 1; (j) <= (m - 1); (j) += (1)) {
      if (s[i][j] == s[i + 1][j] and s[i][j] == s[i][j - 1])
        lol[i][j] = minl(lol[i + 1][j], lol[i][j - 1]) + 1;
    }
  }
  for (long long int(i) = 1; (i) <= (n - 1); (i) += (1)) {
    for (long long int j = m - 2; j >= 0; j--) {
      if (s[i][j] == s[i - 1][j] and s[i][j] == s[i][j + 1])
        ur[i][j] = minl(ur[i - 1][j], ur[i][j + 1]) + 1;
    }
  }
  for (long long int i = n - 2; i >= 0; i--) {
    for (long long int j = m - 2; j >= 0; j--) {
      if (s[i][j] == s[i + 1][j] and s[i][j] == s[i][j + 1])
        lor[i][j] = minl(lor[i + 1][j], lor[i][j + 1]) + 1;
    }
  }
  long long int ct = 0;
  for (long long int(i) = 0; (i) <= (n - 1); (i) += (1)) {
    for (long long int(j) = 0; (j) <= (m - 1); (j) += (1)) {
      ct += (minl(ul[i][j], minl(ur[i][j], minl(lol[i][j], lor[i][j]))));
    }
  }
  wrtline(ct);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
