#include <bits/stdc++.h>
using namespace std;
const long double eps = 0.00000001;
const long long MASK(1 << 10);
typedef long long arr[1007];
typedef long long msk[MASK + 7];
typedef vector<long long> graph[1007];
typedef pair<long long, long long> parr[1007];
typedef long long table[1007][107];
typedef long long arr2[107];
long long n, m, A[1007][1007], V[1007][1007];
vector<long long> T[1007], S[1007], col[1007];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      char ch;
      cin >> ch;
      A[i][j] = ch - 'a' + 1;
    }
  for (long long j = 1; j <= m; j++) {
    for (long long i = 1; i <= n; i++) {
      if (T[j].empty() || A[i][j] != A[i - 1][j]) {
        T[j].push_back(1);
        S[j].push_back(i);
        col[j].push_back(A[i][j]);
      } else
        T[j][T[j].size() - 1]++;
    }
  }
  long long res = 0;
  for (long long j = 1; j <= m; j++) {
    for (long long i = 2; i <= T[j].size() - 1; i++) {
      if (V[j][i - 2] == 1) continue;
      long long si = 0;
      bool check = false;
      if (T[j][i - 2] >= T[j][i - 1] && T[j][i - 1] <= T[j][i]) check = true;
      long long p = j + 1, length = T[j][i - 1];
      if (check) si = 1;
      while (check && p <= m) {
        auto it = lower_bound(S[p].begin(), S[p].end(), S[j][i - 1]);
        long long k = it - S[p].begin();
        if (k + 1 > S[p].size() - 1 || S[p][k] != S[j][i - 1] ||
            T[p][k] != T[j][i - 1])
          check = false;
        if (!check || !(T[p][k - 1] >= T[p][k] && T[p][k] <= T[p][k + 1]))
          check = false;
        if (!check || col[j][i - 2] != col[p][k - 1] ||
            col[j][i - 1] != col[p][k] || col[j][i] != col[p][k + 1])
          check = false;
        if (check) {
          si++;
          V[p][k - 1] = 1;
        }
        p++;
      }
      res += si * (si + 1) / 2;
    }
  }
  cout << res << "\n";
}
