malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int digit, base, pos, n;     long long int sum = 0, sum_1 = 0, weight;     cin >> digit >> base;     pos = digit - 1;     for (int i = 0; i < digit; i++, pos--) {       cin >> n;       weight = base;       if (pos == 0) weight = 1;       for (int j = 1; j < pos; j++) {         weight *= base;       }       sum += n * weight;     }     cin >> digit >> base;     pos = digit - 1;     for (int i = 0; i < digit; i++, pos--) {       cin >> n;       weight = base;       if (pos == 0) weight = 1;       for (int j = 1; j < pos; j++) {         weight *= base;       }       sum_1 += n * weight;     }     if (sum == sum_1)       cout <<  =  << endl;     else if (sum > sum_1)       cout <<  >  << endl;     else       cout <<  <  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 200005;   struct node {     long long ab;     long long cab;   } a[maxn], b[maxn];   struct mon {     long long x, y, z;   } mo[maxn];   bool cmpab(struct node ab1, struct node ab2) { return ab1.ab < ab2.ab; }   bool cmpm(struct mon mo1, struct mon mo2) { return mo1.x < mo2.x; }   struct cmp1 {     bool operator()(const node &a, const node &b) const { return a.ab < b.ab; }   };   long long trb[4 * maxn + 1] = {0}, trbk[4 * maxn + 1] = {0};   void build(long long k, long long l, long long r, long long l1, long long r1,              long long val) {     if (l1 <= l && r <= r1) {       trbk[k] += val;     } else if (!(r < l1 || r1 < l)) {       long long m = (l + r) / 2;       trbk[k * 2 + 2] += trbk[k], trbk[k * 2 + 1] += trbk[k];       trbk[k] = 0;       build(k * 2 + 1, l, m, l1, r1, val);       build(k * 2 + 2, m + 1, r, l1, r1, val);       trb[k] =           max(trb[k * 2 + 1] + trbk[k * 2 + 1], trb[k * 2 + 2] + trbk[k * 2 + 2]);     } else {       return;     }   }   long long cal(long long k, long long l, long long r, long long l1,                 long long r1) {     if (l1 <= l && r <= r1) {       return trb[k] + trbk[k];     } else if (!(r < l1 || r1 < l)) {       long long m = (l + r) / 2;       trbk[k * 2 + 2] += trbk[k], trbk[k * 2 + 1] += trbk[k];       trbk[k] = 0;       trb[k] =           max(trb[k * 2 + 1] + trbk[k * 2 + 1], trb[k * 2 + 2] + trbk[k * 2 + 2]);       long long ans1 = cal(k * 2 + 1, l, m, l1, r1);       long long ans2 = cal(k * 2 + 2, m + 1, r, l1, r1);       return max(ans1, ans2);     } else {       return 0;     }   }   long long bi(long long l, long long r, long long val) {     long long m = (l + r) / 2;     if (l == r) {       return m;     } else if (b[m].ab <= val) {       return bi(m + 1, r, val);     } else {       return bi(l, m, val);     }   }   int main(void) {     long long n, m, p;     scanf( %lld%lld%lld , &n, &m, &p);     for (long long i = 0; i < n; i++) {       scanf( %lld%lld , &a[i].ab, &a[i].cab);     }     for (long long i = 0; i < m; i++) {       scanf( %lld%lld , &b[i].ab, &b[i].cab);     }     for (long long i = 0; i < p; i++) {       scanf( %lld%lld%lld , &mo[i].x, &mo[i].y, &mo[i].z);     }     sort(a, a + n, cmpab);     sort(b, b + m, cmpab);     sort(mo, mo + p, cmpm);     long long ma = -a[0].cab - b[0].cab;     long long monu = 0;     for (long long i = 0; i < m; i++) {       build(0, 0, m - 1, i, i, -b[i].cab);     }     for (long long i = 0; i < n; i++) {       while (a[i].ab > mo[monu].x && monu < p) {         if (mo[monu].y >= b[m - 1].ab) {           monu++;           continue;         }         long long num = bi(0, m - 1, mo[monu].y);         build(0, 0, m - 1, num, m - 1, mo[monu].z);         monu++;       }       ma = max(ma, -a[i].cab + cal(0, 0, m - 1, 0, m - 1));     }     printf( %lld , ma);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long double m, n, c = 0, k = 0, a = 0, b = 0, d;     cin >> m >> n >> c >> d;     long double s1, s2, x, y;     a = (3 * m) / 10;     b = m - (m / 250) * c;     x = (3 * n) / 10;     y = n - (n / 250) * d;     s1 = max(a, b);     s2 = max(x, y);     if (s1 > s2)       cout <<  Misha  << endl;     else if (s1 < s2)       cout <<  Vasya  << endl;     else       cout <<  Tie  << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long res;   const long long mod = 1073741824;   long long d(int a, int b, int c) {     vector<int> q(102, 0);     for (int i = 2; i <= a; i++)       if (a % i == 0) {         while (a % i == 0) {           a /= i;           q[i]++;         }       }     for (int i = 2; i <= b; i++)       if (b % i == 0) {         while (b % i == 0) {           b /= i;           q[i]++;         }       }     for (int i = 2; i <= c; i++)       if (c % i == 0) {         while (c % i == 0) {           c /= i;           q[i]++;         }       }     long long res = 1;     for (int i = 0; i < 102; i++) res = (res * (q[i] + 1)) % mod;     return res;   }   int main() {     int a, b, c;     cin >> a >> b >> c;     for (int i = 1; i <= a; i++)       for (int j = 1; j <= b; j++)         for (int k = 1; k <= c; k++) res = (res % mod + d(i, j, k) % mod) % mod;     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   const int mod = 998244353;   long long d[N][N];   long long p[N];   long long inv[N];   long long _inv[N];   long long f[N];   void init(int n) {     d[0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= i; j++) {         d[i][j] =             (d[i - 1][j - 1] * (i - j + 1) % mod + d[i - 1][j] * j % mod) % mod;       }     }     p[0] = p[1] = inv[0] = inv[1] = _inv[0] = _inv[1] = 1;     for (int i = 2; i <= n; i++) {       p[i] = p[i - 1] * i % mod;       inv[i] = (mod - mod / i) * inv[mod % i] % mod;       _inv[i] = _inv[i - 1] * inv[i] % mod;     }   }   int ans[N];   int main() {     int n;     cin >> n;     init(n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         ans[i] = (ans[i] + d[j][i] * _inv[j] % mod) % mod;       }     for (int i = 1; i <= n; i++) ans[i] = ans[i] * p[n] % mod;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   vector<pair<long long, long long> > g[N];   int n, m;   stack<int> st;   bool inStack[N];   int cmp[N], ind[N], low[N], cnt, cont;   void dfs(int x) {     ind[x] = low[x] = cnt++;     st.push(x);     inStack[x] = true;     for (int i = 0; i < g[x].size(); ++i) {       int y = g[x][i].first;       if (ind[y] == -1) {         dfs(y);         low[x] = min(low[x], low[y]);       } else if (inStack[y]) {         low[x] = min(low[x], ind[y]);       }     }     if (ind[x] == low[x]) {       int idx;       do {         idx = st.top();         st.pop();         inStack[idx] = 0;         cmp[idx] = cont;       } while (idx != x);       cont++;     }   }   inline void initTarjan() { memset(ind, -1, sizeof ind); }   bool componentProcessed[N];   vector<pair<long long, long long> > compressedGraph[N];   long long componentCost[N];   inline long long getCost(long long x) {     long long lo = 0, hi = 1000000LL;     while (lo < hi) {       long long md = (lo + hi + 1) >> 1;       if ((md * (md - 1)) / 2LL <= x)         lo = md;       else         hi = md - 1;     }     return x * lo - lo * (lo + 1) * (lo - 1) / 6LL;   }   long long pd[N];   long long func(int x) {     if (pd[x] != -1) return pd[x];     pd[x] = componentCost[x];     for (int i = 0; i < compressedGraph[x].size(); ++i) {       int y = compressedGraph[x][i].first;       long long w = compressedGraph[x][i].second;       pd[x] = max(pd[x], func(y) + w + componentCost[x]);     }     return pd[x];   }   int main() {     initTarjan();     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       g[a].emplace_back(make_pair(b, c));     }     for (int i = 1; i <= n; ++i) {       if (ind[i] == -1) dfs(i);     }     int s;     scanf( %d , &s);     for (int x = 1; x <= n; ++x) {       for (int j = 0; j < g[x].size(); ++j) {         int y = g[x][j].first;         if (cmp[x] != cmp[y])           compressedGraph[cmp[x]].emplace_back(make_pair(cmp[y], g[x][j].second));         else           componentCost[cmp[x]] += getCost(g[x][j].second);       }     }     memset(pd, -1, sizeof pd);     printf( %lld n , func(cmp[s]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long ar[51];     vector<vector<long long>> price(5);     long long currentBalance = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ar[i];     }     for (int i = 0; i < 5; i++) {       price[i].assign(2, 0);       cin >> price[i][0];     }     for (int i = 0; i < n; i++) {       currentBalance += ar[i];       for (int j = 4; j >= 0; j--) {         int k = currentBalance / price[j][0];         price[j][1] += k;         currentBalance -= k * price[j][0];       }     }     for (int i = 0; i < 5; i++) {       cout << price[i][1] <<    ;     }     cout <<   n  << currentBalance;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long a = 0, b = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) b = -1;       c = getchar();     }     while (isdigit(c)) {       a = a * 10 + c -  0 ;       c = getchar();     }     return a * b;   }   const long long N = 3e5 + 50, M = 6e5 + 50;   long long n, m, w[N], tot, h[N], nx[M], ver[M], ed[M], dat[N * 8], lazy[N * 8],       ans;   void add(long long u, long long v, long long z) {     ver[++tot] = v;     ed[tot] = z;     nx[tot] = h[u];     h[u] = tot;   }   void spread(long long p) {     if (lazy[p]) {       dat[(p << 1)] += lazy[p];       dat[(p << 1 | 1)] += lazy[p];       lazy[(p << 1)] += lazy[p];       lazy[(p << 1 | 1)] += lazy[p];       lazy[p] = 0;     }   }   void change(long long p, long long l, long long r, long long u, long long v,               long long z) {     if (l >= u && r <= v) {       dat[p] += z;       lazy[p] += z;       return;     }     spread(p);     long long mid = (l + r) >> 1;     if (u <= mid) change((p << 1), l, mid, u, v, z);     if (v > mid) change((p << 1 | 1), mid + 1, r, u, v, z);     dat[p] = max(dat[(p << 1)], dat[(p << 1 | 1)]);   }   signed main() {     n = read();     m = read();     for (register long long i = 1; i <= n; i++) {       w[i] = read();     }     for (register long long i = 1, u, v, z; i <= m; i++) {       u = read();       v = read();       z = read();       add(v, u, z);     }     for (register long long i = 1; i <= n; i++) {       change(1, 1, n, i, i, ans);       change(1, 1, n, 1, i, -w[i]);       for (register long long j = h[i]; j; j = nx[j]) {         change(1, 1, n, 1, ver[j], ed[j]);       }       ans = max(ans, dat[1]);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4010;   int n, m, a[N], rt, tot, L[N], siz[N], R[N], ls[N], rs[N];   long long val[N], dp[N][N];   inline void build(int &p, int l, int r) {     if (l > r) return;     p = ++tot;     int pos = l;     for (int i = l; i <= r; ++i)       if (a[i] < a[pos]) pos = i;     val[p] = a[pos];     build(ls[p], l, pos - 1);     build(rs[p], pos + 1, r);     dp[p][0] = 0;     dp[p][1] = m * val[p] - val[p];     siz[p] = 1;     for (int i = siz[p]; i >= 0; --i)       for (int j = 0; j <= siz[ls[p]]; ++j)         dp[p][i + j] =             max(dp[p][i + j], dp[p][i] + dp[ls[p]][j] - 2ll * i * j * val[p]);     siz[p] += siz[ls[p]];     for (int i = siz[p]; i >= 0; --i)       for (int j = 0; j <= siz[rs[p]]; ++j)         dp[p][i + j] =             max(dp[p][i + j], dp[p][i] + dp[rs[p]][j] - 2ll * i * j * val[p]);     siz[p] += siz[rs[p]];   }   int main() {     memset(dp, -0x3f, sizeof(dp));     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     build(rt, 1, n);     printf( %lld n , dp[1][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, w;   int v[100010];   long long mark[100010];   bool test(long long x) {     memset(mark, 0, sizeof mark);     long long qnt = 0;     long long sum = 0;     for (int i = 0; i < n; ++i) {       if (qnt > m) return false;       sum -= mark[i];       long long val = v[i] + sum;       if (val < x) {         qnt += x - val;         mark[min(i + w, n)] += x - val;         sum += x - val;       }     }     return qnt <= m;   }   long long bs(long long lo, long long hi) {     while (hi - lo > 1) {       long long mid = (hi + lo) / 2;       if (test(mid)) {         lo = mid;       } else         hi = mid;     }     if (test(hi)) return hi;     return lo;   }   int main(void) {     cin >> n >> m >> w;     for (int i = 0; i < n; ++i) {       cin >> v[i];     }     cout << bs(0, 1000000000000000LL) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[105][5];   int n, Ans, b[105];   bool check(int i) {     for (int j = 1; j <= n; j++)       for (int k = j + 1; k <= n; k++)         if (i != j && i != k) {           long long tmp = 0;           for (int l = 1; l <= 5; l++)             tmp += (a[j][l] - a[i][l]) * (a[k][l] - a[i][l]);           if (tmp > 0) return 0;         }     return 1;   }   int main() {     scanf( %d , &n);     if (n > 66) {       puts( 0 );     } else {       for (int i = 1; i <= n; i++)         for (int j = 1; j <= 5; j++) scanf( %I64d , &a[i][j]);       for (int i = 1; i <= n; i++) {         Ans += b[i] = check(i);       }       printf( %d n , Ans);       for (int i = 1; i <= n; i++)         if (b[i]) {           printf( %d n , i);         }     }   }
#include <bits/stdc++.h>   using namespace std;   void printReverseStack(stack<int> &ans) {     int x = ans.top();     ans.pop();     if (!ans.empty()) printReverseStack(ans);     cout << x <<    ;   }   int main() {     int n, d, l, x;     stack<int> ans;     cin >> n >> d >> l;     ans.push(d);     while (ans.size() < n) {       x = ans.top();       ans.pop();       if (x <= 0) {         ans.push(1);         ans.push(1 - x);       } else {         ans.push(l);         ans.push(l - x);       }     }     if (ans.top() <= 0 || ans.top() > l)       cout << -1;     else       printReverseStack(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = x * 10 + (c & 15), c = getchar();   }   const int P = 998244353;   int n, m;   char c[500001];   struct matrix {     int n, m, a[3][3];     inline matrix(int n = 0, int m = 0) : n(n), m(m) { memset(a, 0, sizeof(a)); }   } s[500001 << 2];   inline matrix operator*(const matrix &a, const matrix &b) {     matrix c(a.n, b.m);     for (int i = 1; i <= c.n; i++)       for (int k = 1; k <= a.m; k++)         for (int j = 1; j <= c.m; j++)           c.a[i][j] = (c.a[i][j] + (long long)a.a[i][k] * b.a[k][j]) % P;     return c;   }   inline void build(int p, int l, int r) {     if (l == r) {       s[p] = matrix(2, 2), s[p].a[1][2] = (c[l - 1] == 1 ? 9 - c[l] : 0),       s[p].a[2][1] = 1, s[p].a[2][2] = c[l] + 1;       return;     }     int mid = (l + r) >> 1;     build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);     s[p] = s[p << 1] * s[p << 1 | 1];   }   inline void add(int p, int l, int r, int x) {     if (x > r || x < l) return;     if (l == r) {       s[p].a[1][2] = (c[l - 1] == 1 ? 9 - c[l] : 0), s[p].a[2][1] = 1,       s[p].a[2][2] = c[l] + 1;       return;     }     int mid = (l + r) >> 1;     if (mid >= x)       add(p << 1, l, mid, x);     else       add(p << 1 | 1, mid + 1, r, x);     s[p] = s[p << 1] * s[p << 1 | 1];   }   signed main() {     read(n), read(m), scanf( %s , c + 1);     for (int i = 1; i <= n; i++) c[i] -=  0 ;     build(1, 1, n);     while (m--) {       int x, y;       read(x), read(y), c[x] = y, add(1, 1, n, x), add(1, 1, n, x + 1);       matrix ans(1, 2);       ans.a[1][1] = ans.a[1][2] = 1;       ans = ans * s[1];       printf( %d n , ans.a[1][2]);     }     return 0;   }
#include <bits/stdc++.h>   const int32_t MAX_N = 1000;   bool isInA[MAX_N + 5], isInB[MAX_N + 5], isVisited[MAX_N + 5];   std::vector<int32_t> v[MAX_N + 5];   int32_t Dfs(int32_t nd) {     isVisited[nd] = true;     if (isInA[nd]) {       return nd;     }     int32_t ans = INT32_MAX;     for (auto &x : v[nd]) {       if (!isVisited[x]) {         ans = std::min(ans, Dfs(x));       }     }     return ans;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int32_t cntTests;     std::cin >> cntTests;     for (int32_t cs = 1; cs <= cntTests; cs++) {       int32_t n;       std::cin >> n;       for (int32_t i = 1; i <= n; i++) {         v[i].clear();       }       for (int32_t i = 0; i < n - 1; i++) {         int32_t a, b;         std::cin >> a >> b;         v[a].push_back(b);         v[b].push_back(a);       }       memset(isInA, 0, sizeof(isInA));       memset(isInB, 0, sizeof(isInB));       int32_t k1;       std::cin >> k1;       std::vector<int32_t> v1(k1);       for (int32_t i = 0; i < k1; i++) {         std::cin >> v1[i];         isInA[v1[i]] = true;       }       int32_t k2;       std::cin >> k2;       std::vector<int32_t> v2(k2);       for (int32_t i = 0; i < k2; i++) {         std::cin >> v2[i];         isInB[v2[i]] = true;       }       std::cout <<  B   << v2[0] <<   n  << std::flush;       int32_t stNode;       std::cin >> stNode;       memset(isVisited, 0, sizeof(isVisited));       int32_t target = Dfs(stNode);       std::cout <<  A   << target <<   n  << std::flush;       int32_t res;       std::cin >> res;       if (isInB[res]) {         std::cout <<  C   << target <<   n  << std::flush;       } else {         std::cout <<  C   << -1 <<   n  << std::flush;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int a[100000], b[100000], n, i, x, y;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     for (i = 0; i < n; i++) {       if (a[i] != b[i]) {         x = i;         break;       }     }     for (i = n - 1; i >= 0; i--) {       if (a[i] != b[i]) {         y = i;         break;       }     }     reverse(a + x, a + y + 1);     for (i = 0; i < n; i++) {       if (a[i] != b[i]) {         cout <<  no ;         return 0;       }     }     cout <<  yes  << endl << x + 1 <<     << y + 1;   }
#include<bits/stdc++.h>   #define ll long long int   #define mk make_pair   #define pb push_back   #define INF (ll)1e18   #define pii pair<ll,ll>   #define mod 1000000007 //998244353   #define f(i,a,b) for(ll i=a;i<b;i++)   #define fb(i,a,b) for(ll i=a;i>b;i--)   #define ff first   #define ss second   #define srt(v)  if(!v.empty())sort(v.begin(),v.end())   #define rev(v)  if(!v.empty())reverse(v.begin(),v.end())   #define PI 3.141592653589793238   #define pqr priority_queue<ll,vector<ll>,greater<ll>()>   using namespace std;   ll pow_mod(ll a,ll b)   {    ll res=1;    while(b!=0)    {     if(b&1)     {      res=(res*a)%mod;     }     a=(a*a)%mod;     b/=2;    }    return res;   }      ll calc(vector<ll> &a){       ll sz=a.size();       ll ans=0;              for(ll i=1;i<sz;i++){           ll j=i;                      while(j<sz&&a[j]==a[i])++j;                      i=--j;           ++ans;       }              return ans;   }   void solve()   {     ll n;     cin>>n;          ll a[n];          for(ll i=0;i<n;i++){         cin>>a[i];     }          vector<ll>v1,v2;          vector<ll>v[n+1];          for(ll i=1;i<=n;i++){         v[i].pb(INF);     }           for(ll i=n-1;i>=0;i--){         v[a[i]].pb(i);     }                   v1.pb(-1);     v2.pb(-1);               for(ll i=0;i<n;i++){         v[a[i]].pop_back();                  if(v1.back()==a[i]&&v2.back()==a[i]){              v1.pb(a[i]);                 }         else if(v1.back()==a[i]){             v1.pb(a[i]);         }         else if(v2.back()==a[i]){             v2.pb(a[i]);         }         else if(v1.back()==-1)         {             v1.pb(a[i]);         }         else if(v2.back()==-1){             v2.pb(a[i]);         }         else         {                             ll x=v[v1.back()].back();             ll y=v[v2.back()].back();                          if(x<y){                 v2.pb(a[i]);             }             else             v1.pb(a[i]);         }     }              ll ans=calc(v1)+calc(v2);          cout<<ans<<endl;   }   int main()   {    ios_base::sync_with_stdio(false);        cin.tie(NULL);        cout.tie(NULL);           //Start from Here.        ll t;     t=1;   // cin>>t;     while(t--)     solve();        //Good Bye!       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k, n, a[101];   int main() {     ios::sync_with_stdio(0);     cin >> n >> k;     for (int i = (0), _b = (n); i < _b; i++) cin >> a[i];     sort(a, a + n);     cout << a[n - k];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> P;   int m, n;   void bs() {     int lo = 1, hi = m, ans = 0;     int cnt = 0;     while (lo <= hi) {       int mid = (lo + hi) / 2;       cout << mid << endl;       int t;       cin >> t;       if (P[cnt % n] == 0) {         if (t == 0) {           exit(0);         }         if (t == -1) {           lo = mid + 1;         }         if (t == 1) {           hi = mid - 1;         }       }       if (P[cnt % n] == 1) {         if (t == 0) {           exit(0);         }         if (t == 1) {           lo = mid + 1;         }         if (t == -1) {           hi = mid - 1;         }       }       cnt++;     }   }   int main() {     cin >> m >> n;     P = vector<int>(n);     for (int i = 0; i < n; i++) {       cout << 1 << endl;       int t;       cin >> t;       if (t == 0 || t == -2) exit(0);       if (t == 1)         P[i] = 1;       else         P[i] = 0;     }     bs();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   using namespace std;   namespace ywy {   char v[300][300];   long long dk1[300], dk2[300];   int dp[600];   typedef struct _p {     long long h1, h2;     _p() {       h1 = 2333;       h2 = 6663;     }     friend bool operator==(const _p &a, const _p &b) {       return (a.h1 == b.h1 && a.h2 == b.h2);     }     friend bool operator!=(const _p &a, const _p &b) {       return ((a.h1 != b.h1) || (a.h2 != b.h2));     }     inline void insert(char x) {       h1 += dk1[x -  a  + 1];       h1 %= 998244353;       h2 += dk2[x -  a  + 1];       h2 %= 1000000007;     }   } pair;   pair str[600], real[600];   int s[300];   inline int solve(int n) {     int ptr = 0, mid = 1, ans = 0;     for (register int i = 2; i <= n; i++) {       if (mid + ptr < i)         mid = i, ptr = 0, dp[i] = 0;       else         dp[i] = min(mid + ptr - i, dp[mid * 2 - i]);       while (dp[i] < min(n - i, i - 1) &&              str[i + dp[i] + 1] == str[i - dp[i] - 1])         dp[i]++;       if (i + dp[i] >= mid + ptr) mid = i, ptr = dp[i];       if ((i & 1) == 0 && (s[i >> 1] != (s[i >> 1] & -s[i >> 1]))) continue;       ans += (dp[i] + 1) / 2;     }     return (ans);   }   void ywymain() {     int n, m;     cin >> n >> m;     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= m; j++) cin >> v[i][j];     }     dk1[0] = dk2[0] = 1;     for (register int i = 1; i <= 26; i++) {       dk1[i] = (dk1[i - 1] * 233) % 998244353;       dk2[i] = (dk2[i - 1] * 233) % 1000000007;     }     int ans = 0;     for (register int l = 1; l <= m; l++) {       memset(s, 0, sizeof(s));       for (register int i = 1; i <= n * 2 + 1; i++) str[i] = real[i] = _p();       for (register int r = l; r <= m; r++) {         for (register int i = 1; i <= n; i++) {           s[i] ^= (1 << (v[i][r] - 1));           real[i].insert(v[i][r]);           if (s[i] != (s[i] & -s[i])) {             str[i * 2].h1 = i + 19260817;             str[i * 2].h2 = 19260817 - i;           } else             str[i * 2] = real[i];         }         ans += solve(n * 2 + 1);       }     }     cout << ans << endl;   }   }  // namespace ywy   int main() {     ywy::ywymain();     return (0);   }