#include <bits/stdc++.h>
using namespace std;
const int MX = 1005;
int n, m, tob[MX][MX], tor[MX][MX];
char a[MX][MX];
long long res = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j + 1; j--)
      if (a[i][j] == a[i][j + 1])
        tor[i][j] = tor[i][j + 1];
      else
        tor[i][j] = j + 1;
  }
  for (int j = 0; j < m; j++) {
    for (int i = n - 1; i + 1; i--)
      if (a[i][j] == a[i + 1][j])
        tob[i][j] = tob[i + 1][j];
      else
        tob[i][j] = i + 1;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int f = 1, tam = tob[i][j] - i, it = i;
      for (int k = 0; k < 2; k++) {
        it = tob[it][j];
        if (it >= n) {
          f = 0;
          break;
        }
        if (tob[it][j] - it != tam) {
          if (!k || tob[it][j] - it < tam) {
            f = 0;
            break;
          }
        }
      }
      if (f) {
        int mn = m;
        for (int k = 0; k < 3 * tam; k++) mn = min(mn, tor[i + k][j] - j);
        res += mn;
      }
    }
  cout << res << '\n';
  return 0;
}
