malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1145;   int n, m, q, k;   bitset<N> a[51], f, nw, tp, s[N];   unordered_map<bitset<N>, int> mn;   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1, x, y; i <= m; i++) {       scanf( %d , &x);       while (x--) scanf( %d , &y), a[i][y] = 1;     }     k = min(20, m);     for (int i = 0; i < 1 << k; i++) {       f.reset();       for (int j = 1; j <= k; j++)         if (i & (1 << (j - 1))) f ^= a[j];       int ct = __builtin_popcount(i);       if (!mn.count(f) || mn[f] > ct) mn[f] = ct;     }     for (int i = 0; i < 1 << (m - k); i++)       for (int j = 1; j <= (m - k); j++)         if (i & (1 << (j - 1))) s[i] ^= a[k + j];     while (q--) {       int x, y;       scanf( %d , &x);       nw.reset();       int as = 1e7;       if (x == 0) {         puts( 0 );         continue;       }       while (x--) scanf( %d , &y), nw[y] = 1;       for (int i = 0; i < 1 << (m - k); i++) {         int ct = __builtin_popcount(i);         tp = nw ^ s[i];         if (mn[tp]) as = min(as, mn[tp] + ct);       }       if (as == 1e7)         puts( -1 );       else         printf( %d n , as);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     char s[n][m];     int a[n][m];     int x = clock();     char ch;     scanf( %c , &ch);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         s[i][j] = getchar();       }       char ch;       scanf( %c , &ch);       int last_zero = m;       for (int j = m - 1; j >= 0; j--) {         if (s[i][j] ==  0 ) {           last_zero = j;         }         a[i][j] = last_zero;       }     }     int szs[m + 1];     int final_ans = 0;     for (int lhs = 0; lhs < m; lhs++) {       memset(szs, 0, sizeof szs);       for (int i = 0; i < n; i++) {         if (s[i][lhs] ==  1 ) {           int sz = a[i][lhs] - lhs;           szs[sz]++;         }       }       int v = m * szs[m];       int cur_ans = v;       int sum_szs_prevs = szs[m];       for (int i = m - 1; i >= 1; i--) {         v = v - sum_szs_prevs + (i * szs[i]);         cur_ans = max(cur_ans, v);         sum_szs_prevs += szs[i];       }       final_ans = max(cur_ans, final_ans);     }     printf( %d , final_ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmin(T &a, T b) {     a = min(a, b);   }   template <typename T>   void chkmax(T &a, T b) {     a = max(a, b);   }   inline int fread(void) {     int ret = 0, op = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) op = -1;     for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) -  0  + ch;     return ret * op;   }   const int MAXN = 4e5 + 10;   const int MAXM = +10;   int n, m;   struct Tuple {     int val, lm, rm, lp, rp, lt, rt;     Tuple operator+(const Tuple &b) {       Tuple ret;       ret.val = max(max(val, b.val), max(rp + b.lm, rm + b.lp));       ret.lp = max(lp, max(lt + rt + b.lm, rt - lt + b.lp));       ret.rp = max(b.rp, max(b.lt + b.rt + rm, b.lt - b.rt + rp));       ret.lm = max(lm, b.lm - rt + lt);       ret.rm = max(b.rm, rm - b.lt + b.rt);       if (lt > b.rt)         ret.lt = lt + b.lt - b.rt, ret.rt = rt;       else         ret.rt = b.rt - lt + rt, ret.lt = b.lt;       return ret;     }   } t[MAXN << 2];   int a[MAXN], mx;   void build(int x, int l, int r) {     if (l == r) {       t[x].lp = t[x].rp = 1;       t[x].lm = max(a[l], 0), t[x].rm = max(-a[l], 0);       t[x].lt = (a[l] == 1), t[x].rt = (a[l] == -1);       t[x].val = 1;       return;     }     build((x << 1), l, ((l + r) >> 1));     build((x << 1 | 1), ((l + r) >> 1) + 1, r);     t[x] = t[(x << 1)] + t[(x << 1 | 1)];   }   void modify(int x, int l, int r, int pos, int tp) {     if (l > r) return;     if (l == r) {       t[x].lp = t[x].rp = 1;       t[x].lm = max(tp, 0), t[x].rm = max(-tp, 0);       t[x].lt = (tp == 1), t[x].rt = (tp == -1);       t[x].val = 1;       return;     }     if (pos <= ((l + r) >> 1))       modify((x << 1), l, ((l + r) >> 1), pos, tp);     else       modify((x << 1 | 1), ((l + r) >> 1) + 1, r, pos, tp);     t[x] = t[(x << 1)] + t[(x << 1 | 1)];   }   inline void init(void) {     scanf( %d%d , &n, &m);     char ch;     mx = 2 * n - 2;     for (int i = 1; i <= mx; ++i) {       cin >> ch;       if (ch ==  ( )         a[i] = 1;       else         a[i] = -1;     }     build(1, 1, mx);   }   inline void work(void) {     int x, y;     printf( %d n , t[1].val);     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &x, &y);       modify(1, 1, mx, x, a[y]);       modify(1, 1, mx, y, a[x]);       swap(a[x], a[y]);       printf( %d n , t[1].val);     }   }   int main() {     init();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int v[200005];   bool inQ[200005];   vector<pair<int, int> > foo;   int main() {     int n, k, q, p, m, i, j;     bool ok;     pair<int, int> x;     cin >> n >> k >> m;     for (i = 1; i <= n; ++i) cin >> v[i];     priority_queue<pair<int, int> > pq;     for (j = 0; j < m; ++j) {       cin >> q >> p;       if (q == 1) {         if (!inQ[p]) {           pq.push({v[p], p});           inQ[p] = 1;         }       } else {         if (!inQ[p])           ok = 0;         else {           ok = i = 0;           while (!pq.empty() && i < k) {             x = pq.top();             pq.pop();             foo.push_back(x);             if (x.second == p) {               ok = true;               break;             }             ++i;           }           while (!foo.empty()) {             pq.push(foo.back());             foo.pop_back();           }         }         if (ok == true)           cout <<  YES n ;         else           cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ans;   int r, c;   char mp[201][201];   int ma[201][201];   int mac[201][201];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       char s[101];       scanf( %s , &s);       for (int j = 0; j < n; j++) {         mp[i][j] = s[j];       }       getchar();     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (mp[i][j] ==  # ) continue;         int flg1 = 0, flg2 = 0;         for (int kk = 0; kk < m; kk++) {           if (mp[i][j + kk] !=  . ) flg2 = 1;           if (mp[i + kk][j] !=  . ) flg1 = 1;         }         if (flg2 == 0) {           for (int kk = 0; kk < m; kk++) {             if (kk + j < n) ma[i][j + kk]++;             if (ma[i][j + kk] > ans) {               ans = ma[i][j + kk];               r = i;               c = j + kk;             }           }         }         if (flg1 == 0) {           for (int kk = 0; kk < m; kk++) {             if (i + kk < n) ma[i + kk][j]++;             if (ma[i + kk][j] > ans) {               ans = ma[i + kk][j];               r = i + kk;               c = j;             }           }         }       }     }     printf( %d %d , r + 1, c + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int mx[N << 2], lz[N << 2], sum[N << 2], a[N], b[N];   void pushup(int rt) { mx[rt] = max(mx[(rt << 1)], mx[(rt << 1 | 1)]); }   void pushdown(int rt) {     if (lz[rt]) {       lz[(rt << 1)] += lz[rt];       lz[(rt << 1 | 1)] += lz[rt];       mx[(rt << 1)] += lz[rt];       mx[(rt << 1 | 1)] += lz[rt];       lz[rt] = 0;     }   }   void up(int L, int R, int val, int l = 1, int r = 1000000, int rt = 1) {     if (L <= l && R >= r) {       mx[rt] += val;       lz[rt] += val;     } else {       pushdown(rt);       if (((l + r) >> 1) >= L) up(L, R, val, l, ((l + r) >> 1), (rt << 1));       if (((l + r) >> 1) + 1 <= R)         up(L, R, val, ((l + r) >> 1) + 1, r, (rt << 1 | 1));       pushup(rt);     }   }   int f(int l = 1, int r = 1000000, int rt = 1) {     if (l == r) return l;     pushdown(rt);     if (mx[(rt << 1 | 1)] > 0)       return f(((l + r) >> 1) + 1, r, (rt << 1 | 1));     else       return f(l, ((l + r) >> 1), (rt << 1));   }   int main() {     int n, m, q;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), up(1, a[i], 1);     for (int i = 1; i <= m; i++) scanf( %d , &b[i]), up(1, b[i], -1);     scanf( %d , &q);     while (q--) {       int x, i, j;       scanf( %d %d %d , &x, &i, &j);       if (x == 1)         up(1, a[i], -1), up(1, j, 1), a[i] = j;       else         up(1, b[i], 1), up(1, j, -1), b[i] = j;       printf( %d n , mx[1] > 0 ? f() : -1);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000003;   char s[maxn], t[maxn], tt[maxn];   int kmp[maxn];   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %s , s + 1);       int n = strlen(s + 1), p, len = 0;       for (p = 1; p <= n / 2 && s[p] == s[n - p + 1]; p++)         ;       if (p > n / 2) {         puts(s + 1);         continue;       }       for (int i = p; i <= n - p + 1; i++) t[++len] = s[i];       for (int i = 1; i <= len; i++) t[i + len] = t[i];       reverse(t + len + 1, t + len * 2 + 1);       len *= 2;       int pos = 0;       for (int i = 2; i <= len; i++) {         while (pos && t[pos + 1] != t[i]) pos = kmp[pos];         if (t[pos + 1] == t[i]) pos++;         kmp[i] = pos;       }       int tmp = kmp[len];       while (tmp > len / 2) tmp = kmp[tmp];       int ANS1 = (p - 1) * 2 + tmp;       for (int i = 1; i <= len; i++) tt[i] = t[i], kmp[i] = 0;       len = 0;       for (int i = n - p + 1; i >= p; i--) t[++len] = s[i];       for (int i = 1; i <= len; i++) t[i + len] = t[i];       reverse(t + len + 1, t + len * 2 + 1);       len *= 2;       pos = 0;       for (int i = 2; i <= len; i++) {         while (pos && t[pos + 1] != t[i]) pos = kmp[pos];         if (t[pos + 1] == t[i]) pos++;         kmp[i] = pos;       }       tmp = kmp[len];       while (tmp > len / 2) tmp = kmp[tmp];       int ANS2 = (p - 1) * 2 + tmp;       for (int i = 1; i <= len; i++) kmp[i] = 0;       for (int i = 1; i < p; i++) putchar(s[i]);       if (ANS1 > ANS2)         for (int i = 1; i <= ANS1 - (p - 1) * 2; i++) putchar(tt[i]);       else         for (int i = 1; i <= ANS2 - (p - 1) * 2; i++) putchar(t[i]);       for (int i = p - 1; i >= 1; i--) putchar(s[i]);       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, i;     string a, b;     cin >> t;     while (t--) {       vector<int> k;       cin >> n >> a >> b;       for (i = 0; i < n; i++) {         if (a[i] != b[i]) {           k.push_back(i + 1);           k.push_back(1);           k.push_back(i + 1);         }       }       cout << k.size() <<    ;       for (auto x : k) cout << x <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   const int maxn = 1e6 + 2;   const int base = 31;   const int mod = 1e9 + 7;   ll t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> t;     while (t--) {       ll n, x = 0;       cin >> n;       vector<ll> a(n);       for (ll i = 0; i < n; i++) {         cin >> a[i];         x ^= a[i];       }       if (x == 0)         cout <<  DRAW n ;       else {         ll bit = 30;         while (!(x & (1 << bit))) {           --bit;         }         ll k0 = 0, k1 = 0;         for (auto k : a) {           if (k & (1 << bit)) {             k1++;           } else             k0++;         }         assert(k1 % 2 == 1);         if (k0 % 2 == 0 && k1 % 4 == 3) {           cout <<  LOSE  <<   n ;         } else           cout <<  WIN  <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int pi[200015];   void PreKMP(char *P, int n) {     int q, k = 0;     pi[1] = 0;     for (q = 2; q <= n; pi[q++] = k) {       while (k && (P[k] != P[q - 1])) k = pi[k];       if (P[k] == P[q - 1]) k++;     }   }   int KMP(char *T, int n, char *P, int m) {     int i, q = 0;     PreKMP(P, m);     for (i = 1; i <= n; i++) {       while ((q > 0) && (P[q] != T[i - 1])) q = pi[q];       if (P[q] == T[i - 1]) q++;       if (q == m) return m;     }     return q;   }   char a[200015];   char b[200015];   char c[200015];   char cadab[200015];   char cadac[200015];   char cadba[200015];   char cadbc[200015];   char cadca[200015];   char cadcb[200015];   int main() {     while (scanf( %s%s%s , a, b, c) != EOF) {       int sa = strlen(a);       int sb = strlen(b);       int sc = strlen(c);       PreKMP(a, sa);       int ab = KMP(a, sa, b, sb);       int ac = KMP(a, sa, c, sc);       PreKMP(b, sb);       int ba = KMP(b, sb, a, sa);       int bc = KMP(b, sb, c, sc);       PreKMP(c, sc);       int ca = KMP(c, sc, a, sa);       int cb = KMP(c, sc, b, sb);       int minn = sa + sb + sc;       minn = min(minn, sa + (sb - ab) + (sc - bc));       minn = min(minn, sa + (sc - ac) + (sb - cb));       minn = min(minn, sb + (sa - ba) + (sc - ac));       minn = min(minn, sb + (sc - bc) + (sa - ca));       minn = min(minn, sc + (sa - ca) + (sb - ab));       minn = min(minn, sc + (sb - cb) + (sa - ba));       int sab = 0;       int sac = 0;       int sba = 0;       int sbc = 0;       int sca = 0;       int scb = 0;       for (int i = 0; i < sa; i++) {         cadab[sab++] = a[i];         cadac[sac++] = a[i];       }       for (int i = 0; i < sb; i++) {         cadba[sba++] = b[i];         cadbc[sbc++] = b[i];       }       for (int i = 0; i < sc; i++) {         cadca[sca++] = c[i];         cadcb[scb++] = c[i];       }       for (int i = ab; i < sb; i++) {         cadab[sab++] = b[i];       }       for (int i = ac; i < sc; i++) {         cadac[sac++] = c[i];       }       for (int i = ba; i < sa; i++) {         cadba[sba++] = a[i];       }       for (int i = bc; i < sc; i++) {         cadbc[sbc++] = c[i];       }       for (int i = ca; i < sa; i++) {         cadca[sca++] = a[i];       }       for (int i = ac; i < sc; i++) {         cadcb[scb++] = b[i];       }       if (KMP(cadab, sab, c, sc) == sc) minn = min(minn, sab);       if (KMP(cadac, sac, b, sb) == sb) minn = min(minn, sac);       if (KMP(cadba, sba, c, sc) == sc) minn = min(minn, sba);       if (KMP(cadbc, sbc, a, sa) == sa) minn = min(minn, sbc);       if (KMP(cadca, sca, b, sb) == sb) minn = min(minn, sca);       if (KMP(cadcb, scb, a, sa) == sa) minn = min(minn, scb);       printf( %d n , minn);     }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int inf = 10000000;   int arr[100005];   map<int, int> mm;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < (n); i++) {       cin >> arr[i];       mm[arr[i]] = 1;     }     sort(arr, arr + n);     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       if (mm[arr[i]] == 0) continue;       if (arr[i] % k != 0) {         ans++;         continue;       }       if (mm.find(arr[i] / k) != mm.end()) mm[arr[i] / k] = 0;       ans++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[5] = {}, x, y = 0;     cin >> a[0] >> a[1] >> a[2];     for (int d = 0; d < 3; d++) {       for (int c = 0; c < 3; c++) {         if (a[d] > a[c]) swap(a[d], a[c]);       }     }     x = a[1];     if (a[0] > x) y += a[0] - x;     if (a[0] < x) y += x - a[0];     if (a[2] > x) y += a[2] - x;     if (a[2] < x) y += x - a[2];     cout << y;     return 0;   }
#include <bits/stdc++.h>   const long long inf = 0x3f3f3f3f3f3f3f3LL;   const long long mod = (long long)1e9 + 7;   using namespace std;   template <class T>   void smin(T& a, T val) {     if (a > val) a = val;   }   template <class T>   void smax(T& a, T val) {     if (a < val) a = val;   }   const long long N = 100 + 5;   long long dp[N][N][N][2];   vector<long long> prefix_function(string s) {     long long n = (long long)s.length();     vector<long long> pi(n);     for (long long i = 1; i < n; i++) {       long long j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) j++;       pi[i] = j;     }     return pi;   }   string s, t, pat;   vector<long long> pi;   long long solve(long long idx1, long long idx2, long long idx3,                   long long ongoing) {     if (idx3 == (long long)(pat.size())) {       return -inf;     }     if (idx1 == (long long)(s.size()) or idx2 == (long long)(t.size())) {       return 0;     }     long long& ans = dp[idx1][idx2][idx3][ongoing];     if (~ans) return ans;     ans = 0;     if (!ongoing) {       smax(ans, solve(idx1 + 1, idx2, idx3, 0));       smax(ans, solve(idx1, idx2 + 1, idx3, 0));     }     if (s[idx1] == t[idx2]) {       if (s[idx1] == pat[idx3]) {         smax(ans, 1 + solve(idx1 + 1, idx2 + 1, idx3 + 1, 0));       } else {         if (idx3 == 0) {           smax(ans, 1 + solve(idx1 + 1, idx2 + 1, 0, 0));         } else {           smax(ans, solve(idx1, idx2, pi[idx3 - 1], 1));         }       }     }     return ans;   }   string vals =   ;   void path(long long idx1, long long idx2, long long idx3, long long ongoing) {     if (idx1 == (long long)(s.size()) or idx2 == (long long)(t.size())) {       return;     }     long long ans = solve(idx1, idx2, idx3, ongoing);     if (!ongoing) {       if (ans == solve(idx1 + 1, idx2, idx3, 0)) {         path(idx1 + 1, idx2, idx3, 0);         return;       } else if (ans == solve(idx1, idx2 + 1, idx3, 0)) {         path(idx1, idx2 + 1, idx3, 0);         return;       }     }     if (s[idx1] == t[idx2]) {       if (s[idx1] == pat[idx3]) {         vals += s[idx1];         path(idx1 + 1, idx2 + 1, idx3 + 1, 0);       } else {         if (idx3 == 0) {           vals += s[idx1];           path(idx1 + 1, idx2 + 1, 0, 0);         } else {           path(idx1, idx2, pi[idx3 - 1], 1);         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> s >> t >> pat;     memset(dp, -1, sizeof dp);     pi = prefix_function(pat);     solve(0, 0, 0, 0);     path(0, 0, 0, 0);     if ((long long)(vals.size()) == 0) {       cout << 0;       exit(0);     }     cout << vals;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     int n = s.length();     vector<int> v;     for (int i = 0; i < n; i++)       if (i == n - 1 || s[i] != s[i + 1]) v.push_back(i);     if (s.back() ==  b ) v.pop_back();     vector<int> res(n);     for (int p : v) res[p] = 1;     for (int id : res) cout << id <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);     int n;     cin >> n;     if (n <= 3) {       cout << 0 <<   n ;       return 0;     }     int Max = -1, k;     for (int i = 2; i < n; ++i) {       int tp = n / i * (i - 1);       if (n % i >= 1) tp += n % i - 1;       tp -= i - 1;       if (tp > Max) Max = tp, k = i;     }     set<int> Se;     vector<int> SS(n);     int a = n / k, ps = 0;     for (int i = 0; i < a; ++i) {       for (int j = 0; j < k; ++j) {         if (j == k - 1)           ps++;         else           Se.insert(ps++);       }     }     for (; ps < n - 1; ++ps) Se.insert(ps);     for (int i : Se) SS[i] = 1;     bool ok = 0;     while (!ok) {       vector<int> A;       for (int i = 0; i < k; ++i)         if (((int)(Se).size())) {           A.push_back(*Se.begin());           Se.erase(Se.begin());         }       if (((int)(Se).size()) == 0) ok = 1;       cout << ((int)(A).size()) <<    ;       for (int i : A) cout << i + 1 <<    ;       cout << endl;       cout.flush();       int l;       cin >> l;       --l;       for (int i = 0; i < k; ++i) {         if (SS[(i + l) % n]) Se.insert((i + l) % n);       }       if (ok) {         cout << 0 << endl;         cout.flush();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[105][105][105];   int ans[105][105];   int main() {     int n, m, h, x;     cin >> n >> m >> h;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int k = 1; k <= h; k++) a[i][j][k] = 1;     for (int i = 1; i <= m; i++) {       cin >> x;       for (int j = x + 1; j <= h; j++)         for (int k = 1; k <= n; k++) a[k][i][j] = 0;     }     for (int i = 1; i <= n; i++) {       cin >> x;       for (int j = x + 1; j <= h; j++)         for (int k = 1; k <= m; k++) a[i][k][j] = 0;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> x;         if (x == 0)           for (int k = 1; k <= h; k++) a[i][j][k] = 0;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         ans[i][j] = 0;         for (int k = 1; k <= h; k++)           if (a[i][j][k]) ans[i][j]++;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cout << ans[i][j];         if (j == m)           cout << endl;         else           cout <<    ;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long somod = 1e9 + 7;   const long long maxn = 5e4 + 7;   long long cntnode = 1, m, n, a[maxn];   vector<long long> vt[maxn * 31];   long long cac[32][2];   map<long long, vector<long long>> mp;   long long Pow(long long a, long long b) {     long long ans = 1;     for (; b > 0; b >>= 1, a = a * a % somod) {       if (b & 1) ans = ans * a % somod;     }     return ans;   }   void Update(long long x, long long delta) {     for (long long i = 29; i >= 0; i--) {       cac[i][(x >> i & 1)] += delta;     }   }   long long Cal(long long x) {     long long ans = 0;     for (long long i = 29; i >= 0; i--) {       ans += cac[i][(x >> i & 1) ^ 1] * (1 << i);       ans %= somod;     }     return ans;   }   pair<long long, long long> Count(long long curval, long long lastbit) {     mp.clear();     long long f = 0, s = 0;     for (long long i = 1; i <= n; i++) {       long long val = 0;       for (long long j = 29; j >= lastbit; j--) {         val ^= (a[i] & (1 << j));       }       mp[val].push_back(a[i]);     }     for (auto i : mp) {       long long yay = i.first ^ curval;       if (mp.count(yay) == 0) continue;       s += mp[yay].size() * i.second.size();       for (auto j : i.second) Update(j, 1);       for (auto j : mp[yay]) f = f + Cal(j);       f %= somod;       for (auto j : i.second) Update(j, -1);     }     s /= 2;     f = f * Pow(2, somod - 2) % somod;     return {f, s};   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     if (fopen( test.inp ,  r )) freopen( test.inp ,  r , stdin);     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     long long val = 0, ans = 0;     for (long long i = 29; i >= 0; i--) {       pair<long long, long long> cc = Count(val ^ (1 << i), i);       if (cc.second <= m) {         m -= cc.second, ans += cc.first;       } else {         val ^= (1 << i);       }       if (i == 0) {         ans += (val)*m;       }     }     cout << ans % somod <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int a[N], f[N];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int T;     cin >> T;     while (T--) {       int n, k;       scanf( %d , &n);       memset(a, 0, sizeof a);       for (int i = 1; i <= n; i++) f[i] = 1;       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= n; i++)         for (int j = 2 * i; j <= n; j += i)           if (a[i] < a[j]) f[j] = max(f[j], f[i] + 1);       int res = 0;       for (int i = 1; i <= n; i++) res = max(res, f[i]);       printf( %d n , res);     }     return 0;   }