#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300;   long long orign[MAXN], str[2 * MAXN];   int radius[2 * MAXN];   int n, m;   int mp[MAXN][MAXN];   int num[MAXN][26];   long long hashv[MAXN];   long long base[30];   int siz[MAXN];   bool check(int x, int y) {     for (int i = 0; i < 26; i++) {       if (num[x][i] != num[y][i]) return false;     }     return true;   }   void Manacher(int len, int mark = 0) {     for (int i = 0; i < len; i++) {       str[2 * i + 1] = orign[i];       str[2 * i] = mark;     }     str[2 * len] = mark;     len = 2 * len + 1;     int max_right = 0, pos = 0;     for (int i = 0; i < len; i++) {       if (i < max_right)         radius[i] = min(radius[2 * pos - i], max_right - i);       else         radius[i] = 1;       while (i - radius[i] >= 0 && i + radius[i] < len &&              str[i - radius[i]] > -1 && str[i + radius[i]] > -1 &&              check(str[i - radius[i]], str[i + radius[i]])) {         radius[i]++;       }       if (i + radius[i] >= max_right) {         max_right = i + radius[i];         pos = i;       }     }   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     base[0] = 1;     for (int i = 1; i <= 26; i++) base[i] = base[i - 1] * 2;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         char ch;         cin >> ch;         mp[i][j] = ch -  a ;       }     }     long long ans = 0;     for (int l = 1; l <= m; l++) {       memset(num, 0, sizeof(num));       memset(hashv, 0, sizeof(hashv));       memset(siz, 0, sizeof(siz));       for (int r = l; r <= m; r++) {         for (int i = 1; i <= n; i++) {           int id = mp[i][r];           num[i][id]++;           hashv[i] += base[id];           if (num[i][id] & 1)             siz[i]++;           else             siz[i]--;           if (siz[i] > 1)             orign[i - 1] = -i;           else             orign[i - 1] = i;         }         Manacher(n);         for (int i = 0; i < 2 * n + 1; i++) {           if (str[i] > -1) ans += radius[i] / 2;         }       }     }     cout << ans << endl;     return 0;   }   