#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> ar(n);
  for (int i = 0; i < n; i++) cin >> ar[i];
  vector<vector<int> > up(n, vector<int>(m));
  vector<vector<int> > down(n, vector<int>(m));
  vector<vector<int> > dp(n, vector<int>(m));
  for (int j = 0; j < m; j++) {
    int x = 0;
    char ch = '*';
    for (int i = 0; i < n; i++) {
      if (ch == ar[i][j]) {
        x++;
        up[i][j] = x;
      } else {
        up[i][j] = 1;
        x = 1;
        ch = ar[i][j];
      }
    }
  }
  for (int j = 0; j < m; j++) {
    int x = 0;
    char ch = '*';
    for (int i = n - 1; i >= 0; i--) {
      if (ch == ar[i][j]) {
        x++;
        down[i][j] = x;
      } else {
        down[i][j] = 1;
        x = 1;
        ch = ar[i][j];
      }
    }
  }
  vector<vector<int> > left(n, vector<int>(m));
  vector<vector<int> > ul(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    int pre = -1, x = 0;
    char ch = '*';
    for (int j = 0; j < m; j++) {
      if (pre == up[i][j] && ch == ar[i][j]) {
        x++;
        left[i][j] = x;
      } else {
        left[i][j] = 1;
        x = 1;
        ch = ar[i][j];
        pre = up[i][j];
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    int pre = -1, x = 0;
    char ch = '*';
    for (int j = 0; j < m; j++) {
      if (pre == down[i][j] && ch == ar[i][j]) {
        x++;
        ul[i][j] = x;
      } else {
        ul[i][j] = 1;
        x = 1;
        ch = ar[i][j];
        pre = down[i][j];
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int h = up[i][j];
      if (i - 3 * h + 1 >= 0 && ar[i][j] != ar[i - h][j] &&
          ar[i - h][j] != ar[i - 2 * h][j] && up[i][j] == up[i - h][j] &&
          up[i - 2 * h][j] >= up[i][j]) {
        long long k =
            min(left[i][j], min(left[i - h][j], ul[i - 3 * h + 1][j]));
        ans += k;
      }
    }
  }
  cout << ans;
  return 0;
}
