#include <bits/stdc++.h>
using namespace std;
long long h, c, kq = 0, u[2001][2001], d[2001][2001];
string s[2001];
int main() {
  cin >> h >> c;
  for (int i = 1; i <= h; i++) {
    cin >> s[i];
    s[i] = '0' + s[i];
    if (i == 1 || i == h) {
      for (int e = 1; e <= c; e++) {
        if (i == 1) {
          u[i][e] = 1;
        } else {
          d[i][e] = 1;
        }
      }
    }
  }
  for (int i = 1; i <= h; i++) {
    int cur = 1;
    for (int e = 1; e <= c; e++) {
      if (e == 1 || s[i][e] != s[i][e - 1]) {
        cur = 1;
      } else {
        cur++;
      }
      int cur1 = cur - (cur + 1) % 2;
      if (i != 1 && e != 1 && s[i][e] == s[i - 1][e - 1]) {
        u[i][e] = min(cur1 * 1ll, u[i - 1][e - 1] + 2);
      }
      u[i][e] = max(u[i][e], 1ll);
    }
  }
  for (int i = h; i >= 1; i--) {
    int cur = 1;
    for (int e = 1; e <= c; e++) {
      if (e == 1 || s[i][e] != s[i][e - 1]) {
        cur = 1;
      } else {
        cur++;
      }
      int cur1 = cur - (cur + 1) % 2;
      if (i != h && e != 1 && s[i][e] == s[i + 1][e - 1]) {
        d[i][e] = min(cur1 * 1ll, d[i + 1][e - 1] + 2);
      }
      d[i][e] = max(d[i][e], 1ll);
      kq += (min(d[i][e], u[i][e]) + 1) / 2;
    }
  }
  cout << kq;
}
