#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 9;
const long long inf = 1e18 + 18;
const int max6 = 1e6 + 6;
const int modx = 1e9 + 123;
const int mody = 997;
const int base = 137;
int a[2001][2001];
int f[2001][2001];
int b[2001][2001];
int g[2001][2001];
int main() {
  int m, n;
  cin >> m >> n;
  for (int i = 1; i <= m; ++i) {
    string s;
    cin >> s;
    for (int j = 1; j <= n; ++j) a[i][j] = s[j - 1] - 'a';
  }
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j) {
      int pre = (i > 1 && a[i - 1][j] == a[i][j]) ? b[i - 1][j] : 0;
      if (pre == 0) {
        b[i][j] = 1;
        continue;
      }
      int best = pre - 1;
      if (i + pre - 1 <= m && a[i + pre - 1][j] == a[i][j]) {
        best++;
        if (i + pre <= m && a[i + pre][j] == a[i][j]) best++;
      }
      b[i][j] = best;
    }
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j) {
      int pre = (j > 1 && a[i][j - 1] == a[i][j]) ? f[i][j - 1] : 0;
      if (b[i][j] > pre)
        f[i][j] = pre + 1;
      else
        f[i][j] = b[i][j];
      int tmp = min({i, j, m - i + 1, n - j + 1});
      f[i][j] = min(f[i][j], tmp);
    }
  for (int i = 1; i <= m; ++i)
    for (int j = n; j >= 1; --j) {
      int pre = (j < n && a[i][j + 1] == a[i][j]) ? g[i][j + 1] : 0;
      if (b[i][j] > pre)
        g[i][j] = pre + 1;
      else
        g[i][j] = b[i][j];
      int tmp = min({i, j, m - i + 1, n - j + 1});
      g[i][j] = min(g[i][j], tmp);
    }
  long long res = 0;
  cerr << f[4][5];
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j) {
      int tmp = min(f[i][j], g[i][j]);
      res += tmp;
    }
  cout << res;
}
