#include <bits/stdc++.h>
using namespace std;
int n, m;
int t[501][26], r[501], w[501];
int flag[501][2], v[501], Base[26] = {1};
long long ans;
char s[501][501];
void manacher() {
  int now = 19260817;
  for (int i = 1; i <= n; i++)
    w[i << 1] = (flag[i][1] > 1 ? now++ : v[i]), w[i << 1 | 1] = -1;
  w[0] = -2, w[1] = -1, w[(n + 1) << 1] = -3;
  int mx = 0, p = 0;
  for (int i = 1; i <= (n << 1 | 1); i++) {
    r[i] = max(min(mx - i, 2 * p - i >= 0 ? r[2 * p - i] : 0), 0);
    while (w[i - r[i]] == w[i + r[i]]) r[i]++;
    if (i + r[i] > mx) mx = i + r[i], p = i;
    if (w[i] < 19260817) ans += r[i] / 2;
  }
}
int main() {
  for (int i = 1; i < 26; i++)
    Base[i] = (long long)2333 * Base[i - 1] % 19260817;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int l = 1; l <= m; l++) {
    for (int i = 1; i <= n; i++) {
      memset(t[i], 0, sizeof(t[i]));
      flag[i][0] = flag[i][1] = v[i] = 0;
    }
    for (int r = l; r <= m; r++) {
      for (int i = 1; i <= n; i++) {
        int ch = s[i][r] - 'a';
        flag[i][t[i][ch] & 1]--, t[i][ch]++;
        v[i] = (v[i] + Base[ch]) % 19260817;
        flag[i][t[i][ch] & 1]++;
      }
      manacher();
    }
  }
  printf("%lld\n", ans);
  return 0;
}
