#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 7;
int n, m, k, ar[maxn];
char ch[maxn][maxn];
long long ans = 0;
int nn[maxn][30], len[maxn];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", ch[i] + 1);
  ans = 0;
  for (int i = 1; i <= m; i++) {
    memset(nn, 0, sizeof(nn));
    memset(ar, 0, sizeof(ar));
    for (int j = i; j <= m; j++) {
      for (int k = 1; k <= n; k++) {
        nn[k * 2 - 1][ch[k][j] - 'a']++;
        if (nn[k * 2 - 1][ch[k][j] - 'a'] & 1)
          ar[k * 2 - 1]++;
        else
          ar[k * 2 - 1]--;
      }
      memset(len, 0, sizeof(len));
      int op = 0, mx = 0;
      for (int k = 1; k < n * 2; k++) {
        if (op + mx > k) {
          len[k] = min(len[op * 2 - k], op + mx - k);
        } else
          len[k] = ar[k] <= 1;
        while (k - len[k] >= 0 && k + len[k] <= 2 * n) {
          bool fond = 1;
          if (ar[k - len[k]] > 1 || ar[k + len[k]] > 1) {
            fond = 0;
          }
          for (int r = 0; r < 26; r++) {
            if (nn[k - len[k]][r] != nn[k + len[k]][r]) {
              fond = 0;
              break;
            }
          }
          if (!fond)
            break;
          else {
            len[k]++;
          }
        }
        if (k + len[k] > op + mx) {
          op = k;
          mx = len[k];
        }
        ans += len[k] / 2;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
