#include <bits/stdc++.h>
using namespace std;
long long const N = 1e5 + 5, mod = 1e9 + 7;
long long n, m, k, ans[1005][1005], i, j, matric[1005][1005], t, tt, ttt;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      char x;
      cin >> x;
      matric[i][j] = int(x);
    }
  }
  bool flag;
  long long hast1 = 0, hast2 = 0, hast3 = 0;
  for (i = n - 1; i >= 0; --i) {
    for (j = m - 1; j >= 0; --j) {
      flag = true;
      hast1 = 0, hast2 = 0, hast3 = 0;
      for (t = i; t < n; ++t) {
        if (matric[i][j] == matric[t][j])
          hast1++;
        else
          break;
        if (matric[t][j] != matric[t][j + 1]) flag = false;
      }
      tt = t;
      for (; t < n; ++t) {
        if (matric[tt][j] == matric[t][j])
          hast2++;
        else
          break;
        if (matric[t][j] != matric[t][j + 1]) flag = false;
      }
      ttt = t;
      for (; t < n; ++t) {
        if (matric[ttt][j] == matric[t][j])
          hast3++;
        else
          break;
        if (matric[t][j] != matric[t][j + 1] && hast3 <= hast2) flag = false;
      }
      if (hast1 == hast2 && hast2 <= hast3) ans[i][j]++;
      if (flag && hast1 == hast2 && hast2 <= hast3) ans[i][j] += ans[i][j + 1];
    }
  }
  long long answer = 0;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m; ++j) {
      answer += ans[i][j];
    }
  }
  cout << answer << endl;
  return 0;
}
