#include <bits/stdc++.h>
using namespace ::std;
const int SIZE = 251, MAXC = 26;
char Mat[SIZE][SIZE];
int TA[SIZE][SIZE][MAXC];
bool isPalinRow(int ci, int cf, int row) {
  int fi = 0;
  for (int i = 0; i < MAXC; i++) {
    int aux = TA[row][cf][i] - TA[row][ci - 1][i];
    fi += aux % 2;
  }
  return fi <= 1;
}
bool isPalinCol(int ci, int cf, int r1, int r2) {
  for (int i = 0; i < MAXC; i++) {
    int aux1 = TA[r1][cf][i] - TA[r1][ci - 1][i];
    int aux2 = TA[r2][cf][i] - TA[r2][ci - 1][i];
    if (aux1 != aux2) return false;
  }
  return true;
}
bool IsValid(int ci, int cf, int r1, int r2, std::vector<int> &L) {
  if (L[r1] == 0 || !isPalinRow(ci, cf, r2 / 2)) return false;
  return isPalinCol(ci, cf, r1 / 2, r2 / 2);
}
int Manacher(int ci, int cf, int N) {
  N = 2 * N + 1;
  std::vector<int> L(N, 0);
  L[1] = isPalinRow(ci, cf, 0);
  int c = 1;
  for (int i = 2; i < N; i++) {
    int iMirror = 2 * c - i;
    int diff = (c + L[c]) - i;
    if (diff > 0) L[i] = min(diff, L[iMirror]);
    if (L[i] == 0 && (i & 1)) {
      if (isPalinRow(ci, cf, i / 2))
        L[i] = 1;
      else
        continue;
    }
    while (((i + L[i] + 1) < N && (i - L[i] - 1) >= 0) &&
           ((i + L[i] + 1) % 2 == 0 ||
            IsValid(ci, cf, (i - L[i] - 1), (i + L[i] + 1), L)))
      L[i]++;
    if (i + L[i] > c + L[c]) c = i;
  }
  int ret = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2)
      L[i] = (L[i] + 1) / 2;
    else
      L[i] /= 2;
    ret += L[i];
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= M; j++) {
      cin >> Mat[i][j];
      for (int k = 0; k < MAXC; k++) TA[i][j][k] = TA[i][j - 1][k];
      int c = Mat[i][j] - 'a';
      TA[i][j][c]++;
    }
  }
  long long sol = 0;
  for (int c1 = 1; c1 <= M; c1++) {
    for (int c2 = c1; c2 <= M; c2++) {
      int tmp = Manacher(c1, c2, N);
      sol += tmp;
      cerr << c1 << ' ' << c2 << ' ' << tmp << '\n';
    }
  }
  cout << sol << '\n';
  return 0;
}
