#include <bits/stdc++.h>
using namespace std;
struct node {
  int left, right, rhombus;
  node(int a, int b, int c) { rhombus = a, left = b, right = c; }
};
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> grid(n);
  for (int i = 0; i < n; i++) {
    cin >> grid[i];
  }
  vector<vector<node>> ans(n, vector<node>(m, node(1, 0, 0)));
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (j >= 1 && grid[i][j] == grid[i + 1][j - 1]) {
        ans[i][j].left = ans[i + 1][j - 1].left + 1;
      } else
        ans[i][j].left = 0;
      if (j < m - 1 && grid[i][j] == grid[i + 1][j + 1]) {
        ans[i][j].right = ans[i + 1][j + 1].right + 1;
      } else
        ans[i][j].right = 0;
      if (grid[i][j] != grid[i + 1][j]) {
        ans[i][j].rhombus = 1;
        continue;
      }
      int res = min({ans[i][j].left, ans[i][j].right, ans[i + 1][j].rhombus});
      if (res == ans[i + 1][j].rhombus) {
        if (j - res < 0 || j + res >= m) {
          ans[i][j].rhombus = res;
        } else {
          int p, q, r, s;
          p = i + res, q = j - res, r = i + res, s = j + res;
          if (ans[p][q].right >= res && ans[r][s].left >= res) {
            ans[i][j].rhombus = res + 1;
          } else {
            ans[i][j].rhombus = res;
          }
        }
      } else {
        ans[i][j].rhombus = res + 1;
      }
    }
  }
  long long total = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      total += ans[i][j].rhombus;
    }
  }
  cout << total << '\n';
}
