#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
template <typename T>
void printV(const T &t) {
  std::copy(t.cbegin(), t.cend(),
            std::ostream_iterator<typename T::value_type>(std::cout, " "));
  cout << "\n";
}
template <typename T>
void printVV(const T &t) {
  for (int i = 0; i < t.size(); i++) {
    printf("%d: ", i);
    printV(t[i]);
  }
}
template <typename T, typename S>
void printVP(vector<pair<T, S>> vp) {
  if (vp.empty()) {
    cout << "\n";
    return;
  }
  for (int i = 0; i < vp.size() - 1; i++) {
    cout << "(" << vp[i].first << " " << vp[i].second << ") ";
  }
  cout << "(" << vp[vp.size() - 1].first << " " << vp[vp.size() - 1].second
       << ")\n";
}
template <typename T, typename S>
void printVVP(vector<vector<pair<T, S>>> vvp) {
  for (int i = 0; i < vvp.size(); i++) {
    cout << i << ": ";
    printVP(vvp[i]);
  }
}
vector<string> split(const string &s, char delim) {
  vector<string> result;
  stringstream ss(s);
  string item;
  while (getline(ss, item, delim)) {
    result.push_back(item);
  }
  return result;
}
bool is_number(const string &s) {
  string::const_iterator it = s.begin();
  while (it != s.end() && isdigit(*it)) ++it;
  return !s.empty() && it == s.end();
}
void fast() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
struct Can {
  long long x, r, id;
};
bool compareByX(const Can &lhs, const Can &rhs) { return lhs.x < rhs.x; }
class Person {
 public:
  string name, speak;
  unordered_set<string> understands;
  friend ostream &operator<<(ostream &os, const Person &p) {
    os << p.name << '(' << p.speak << "):";
    for (auto s : p.understands) os << " " << s;
    return os;
  }
};
vector<pair<int, int>> deltas = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
const int INF = 1e9 + 10;
const long long inf = 1e18;
const long double PI = 3.14159265359;
int main() {
  int R, C;
  cin >> R >> C;
  vector<vector<char>> mat(R, vector<char>(C));
  for (int r = 0; r < (R); ++r)
    for (int c = 0; c < (C); ++c) {
      cin >> mat[r][c];
    }
  vector<vector<int>> dp(R, vector<int>(C, 0));
  for (int i = 0; i < R; ++i) {
    for (int j = 0; j < C; ++j) {
      dp[i][j] = 1;
      if (!(i >= 2 && j - 1 >= 0 && j + 1 < C)) continue;
      if (mat[i][j] == mat[i - 1][j - 1] && mat[i][j] == mat[i - 1][j] &&
          mat[i][j] == mat[i - 1][j + 1] && mat[i][j] == mat[i - 2][j]) {
        int r1 = dp[i - 1][j - 1];
        int r2 = dp[i - 1][j];
        int r3 = dp[i - 1][j + 1];
        int r4 = dp[i - 2][j];
        dp[i][j] = min(min(r1, r2), min(r3, r4)) + 1;
      }
    }
  }
  long long ans = 0;
  for (int r = 0; r < (R); ++r)
    for (int c = 0; c < (C); ++c) ans += dp[r][c];
  cout << ans << '\n';
}
