#include <bits/stdc++.h>
using namespace std;
char inp[1000][1000];
int counti[1000][1000];
int flagg[1000][1000];
long long hashe1[1001][1001];
long long hashe2[1001][1001];
int n, m;
void givecount(void) {
  for (int j = 0; j < m; j++) {
    counti[n - 1][j] = 1;
    for (int i = n - 2; i >= 0; i--) {
      if (inp[i][j] == inp[i + 1][j])
        counti[i][j] = counti[i + 1][j] + 1;
      else
        counti[i][j] = 1;
    }
  }
}
void computehash1() {
  long long p1 = 31;
  long long mod1 = 1e9 + 9;
  for (int j = 0; j < m; j++) {
    long long hash_value = 0;
    long long p_pow = 1;
    for (int i = 1; i <= n; i++) {
      p_pow = (p_pow * p1) % mod1;
      hash_value = (hash_value +
                    (long long)((long long)(inp[i - 1][j] - 'a' + 1) * p_pow)) %
                   mod1;
      hashe1[i][j] = hash_value;
    }
  }
}
void computehash2() {
  long long p1 = 37;
  long long mod1 = 1e9 + 7;
  for (int j = 0; j < m; j++) {
    long long hash_value = 0;
    long long p_pow = 1;
    for (int i = 1; i <= n; i++) {
      p_pow = (p_pow * p1) % mod1;
      hash_value = (hash_value +
                    (long long)((long long)(inp[i - 1][j] - 'a' + 1) * p_pow)) %
                   mod1;
      hashe2[i][j] = hash_value;
    }
  }
}
int checkflag(int i, int j) {
  int x = i;
  int y = i + counti[x][j];
  if (y >= n) return 0;
  int z = y + counti[y][j];
  if (z >= n) return 0;
  if (counti[x][j] == counti[y][j] && inp[x][j] != inp[y][j] &&
      (counti[z][j] >= counti[y][j]) && inp[y][j] != inp[z][j]) {
    return 3 * counti[i][j];
  }
  return 0;
}
void giveflag(void) {
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      flagg[i][j] = checkflag(i, j);
    }
  }
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> inp[i][j];
  givecount();
  giveflag();
  computehash1();
  computehash2();
  long long output = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (flagg[i][j] > 0) {
        long long temp = 1;
        while (
            (j + 1) < m && flagg[i][j] == flagg[i][j + 1] &&
            (fabs((hashe1[i + flagg[i][j]][j] - hashe1[i][j])) ==
                 fabs(
                     (hashe1[i + flagg[i][j + 1]][j + 1] - hashe1[i][j + 1])) ||
             (1000000009 - fabs((hashe1[i + flagg[i][j]][j] - hashe1[i][j]))) ==
                 fabs((hashe1[i + flagg[i][j + 1]][j + 1] -
                       hashe1[i][j + 1]))) &&
            (fabs((hashe2[i + flagg[i][j]][j] - hashe2[i][j])) ==
                 fabs(
                     (hashe2[i + flagg[i][j + 1]][j + 1] - hashe2[i][j + 1])) ||
             (1000000007 - fabs((hashe2[i + flagg[i][j]][j] - hashe2[i][j]))) ==
                 fabs((hashe2[i + flagg[i][j + 1]][j + 1] -
                       hashe2[i][j + 1])))) {
          temp++;
          j++;
        }
        output += (temp * (temp + 1)) / 2;
      }
    }
  }
  cout << output;
  return 0;
}
