#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<char>> V(n, vector<char>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> V[i][j];
    }
  }
  vector<vector<int>> intervals(n + m);
  for (int num = 0; num < n + m - 1; ++num) {
    int first = max(0, num - m + 1);
    int last = min(n - 1, num);
    intervals[num].push_back(first);
    for (int i = first + 1; i <= last; ++i) {
      if (V[i][num - i] != V[i - 1][num - i + 1]) {
        intervals[num].push_back(i);
      }
    }
    intervals[num].push_back(last + 1);
  }
  vector<vector<int>> lvl(n, vector<int>(m, 1));
  for (int i = 1; i < n - 1; ++i) {
    for (int j = 1; j < m - 1; ++j) {
      if (V[i][j] == V[i - 1][j] && V[i][j] == V[i][j - 1]) {
        lvl[i][j] = min(lvl[i - 1][j], lvl[i][j - 1]) - 1;
        if (lvl[i][j] == 0) ++lvl[i][j];
      } else {
        lvl[i][j] = 1;
        continue;
      }
      int i1 = i + lvl[i][j];
      if (i1 >= n) continue;
      if (V[i1][j] != V[i][j]) continue;
      int num1 = i1 + j;
      int first =
          upper_bound(intervals[num1].begin(), intervals[num1].end(), i1) -
          intervals[num1].begin();
      --first;
      if (intervals[num1][first] <= i) {
        ++lvl[i][j];
        if (min(lvl[i - 1][j], lvl[i][j - 1]) == 1) continue;
        ++i1;
        ++num1;
        if (i1 >= n) continue;
        if (V[i1][j] != V[i][j]) continue;
        int first2 =
            upper_bound(intervals[num1].begin(), intervals[num1].end(), i1) -
            intervals[num1].begin();
        --first2;
        if (intervals[num1][first2] <= i) {
          lvl[i][j] += 1;
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      ans += lvl[i][j];
    }
  }
  cout << ans;
  return 0;
}
