#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
char a[N][N];
int res[N][N];
vector<int> d1[N + N], d2[N + N];
vector<int> go1[N + N], go2[N + N];
int findIndex(int tp, int x, int id) {
  if (x <= m - 1) return id;
  return id - (x - m + 1);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf(" %c", &a[i][j]);
      d1[i + j].push_back(a[i][j]);
    }
  }
  for (int i = 0; i < n + m - 1; i++) {
    go1[i].resize((int)d1[i].size());
    for (int j = (int)d1[i].size() - 1; j >= 0; j--) {
      if (j == (int)d1[i].size() - 1) {
        go1[i][j] = 1;
      } else {
        if (d1[i][j] == d1[i][j + 1]) {
          go1[i][j] = go1[i][j + 1] + 1;
        } else {
          go1[i][j] = 1;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j >= 0; j--) {
      d2[i + m - 1 - j].push_back(a[i][j]);
    }
  }
  for (int i = 0; i < n + m - 1; i++) {
    go2[i].resize((int)d2[i].size());
    for (int j = (int)d2[i].size() - 1; j >= 0; j--) {
      if (j == (int)d2[i].size() - 1) {
        go2[i][j] = 1;
      } else {
        if (d2[i][j] == d2[i][j + 1]) {
          go2[i][j] = go2[i][j + 1] + 1;
        } else {
          go2[i][j] = 1;
        }
      }
    }
  }
  long long answ = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i == 0) {
        res[i][j] = 1;
      } else {
        res[i][j] = max(res[i - 1][j] - 1, 1);
        while (i - res[i][j] >= 0 && i + res[i][j] < n && j - res[i][j] >= 0 &&
               j + res[i][j] < m) {
          bool flag = true;
          int nx = i - res[i][j], nu = j;
          if (a[nx][nu] != a[i][j]) break;
          if (go1[nx + nu][findIndex(1, nx + nu, nx)] < res[i][j] + 1)
            flag = false;
          if (go2[nx + m - 1 - nu][findIndex(2, nx + m - 1 - nu, nx)] <
              res[i][j] + 1)
            flag = false;
          nx = i, nu = j - res[i][j];
          if (go2[nx + m - 1 - nu][findIndex(2, nx + m - 1 - nu, nx)] <
              res[i][j] + 1)
            flag = false;
          nx = i, nu = j + res[i][j];
          if (go1[nx + nu][findIndex(1, nx + nu, nx)] < res[i][j] + 1)
            flag = false;
          if (flag) {
            ++res[i][j];
          } else {
            break;
          }
        }
      }
      answ += res[i][j];
    }
  }
  cout << answ << endl;
  return 0;
}
