malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e3 + 5;   const int MOD = 1e9 + 7;   int N, M, A, B;   int G[MAXN * MAXN], X, Y, Z;   int H[MAXN][MAXN];   int P[MAXN][MAXN];   int T[MAXN][MAXN];   long long ans;   deque<pair<int, int> > qu;   void reset() { qu.clear(); }   void push(int v, int p) {     while (qu.size() && qu.back().first >= v) {       qu.pop_back();     }     qu.push_back({v, p});   }   int pop(int p) {     while (qu.size() && qu.front().second < p) {       qu.pop_front();     }     assert(qu.size());     return qu.front().first;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N >> M >> A >> B;     cin >> G[0] >> X >> Y >> Z;     for (int i = 1; i < N * M; i++) {       G[i] = (1LL * G[i - 1] * X + Y) % Z;     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         H[i][j] = G[i * M + j];       }     }     for (int i = 0; i < N; i++) {       reset();       for (int j = 0; j < B; j++) push(H[i][j], j);       P[i][B - 1] = pop(0);       for (int j = B; j < M; j++) {         push(H[i][j], j);         P[i][j] = pop(j - B + 1);       }     }     for (int j = B - 1; j < M; j++) {       reset();       for (int i = 0; i < A; i++) push(P[i][j], i);       ans += pop(0);       for (int i = A; i < N; i++) {         push(P[i][j], i);         ans += pop(i - A + 1);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int withoutzero(int x);   int main() {     int a, b, c, d, e, f;     cin >> a >> b;     d = withoutzero(a);     e = withoutzero(b);     c = a + b;     f = withoutzero(c);     if ((d + e) == f) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }   int withoutzero(int x) {     int arr[10], i = 0, t = 0, k = 0;     while (x > 0) {       arr[i] = x % 10;       x = x / 10;       i++;     }     for (int j = 0; j < i; j++) {       if (arr[j] != 0) {         t += arr[j] * pow(10, k);         k++;       }     }     return t;   }
#include <bits/stdc++.h>   using namespace std;   long long f[100000 + 1], a[100000 + 1], n, d, b;   int main() {     scanf( %lld%lld%lld , &n, &d, &b);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     f[0] = 0;     for (int i = 1; i <= n; i++) f[i] += f[i - 1] + a[i];     long long a1 = 0, a2 = 0;     for (long long i = 1; i <= n / 2; i++) {       if (f[min(n, i + i * d)] >= (a1 + 1) * b) ++a1;       if (f[n] - f[max((long long)1, n - i - i * d)] >= (a2 + 1) * b) ++a2;     }     printf( %lld , n / 2 - min(a1, a2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, k, ans1, ans2;   long long a[1010][1010];   long long c[1010], x, y, s, t, temp;      int main() {       scanf( %d%d , &n, &m);       for (i = 0; i < m; i++) {           for (j = 1; j <= n; j++) {               scanf( %lld , &a[i][j]);               c[i] += a[i][j];           }       }       x = (c[m - 1] - c[0]) / (m - 1);       for (i = 1; i < m; i++) {           if ((c[i] - c[0]) != x * i) {               ans1 = i;               y = c[i] - c[0] - x * i;               break;           }       }       for (i = 1; i < m - 1; i++) {           if (i - 1 != ans1 && i != ans1 && i + 1 != ans1) {               x = 0;               for (j = 1; j <= n; j++) {                   x += a[i - 1][j] * a[i - 1][j] + a[i + 1][j] * a[i + 1][j] -                        a[i][j] * a[i][j] * 2;               }               break;           }       }       i = ans1;       t = s = 0;       for (j = 1; j <= n; j++) {           s += a[i - 1][j] * a[i - 1][j] + a[i + 1][j] * a[i + 1][j];           t += a[i][j] * a[i][j] * 2;       }       s -= x;       for (j = 1; j <= n; j++) {           temp = t - a[i][j] * a[i][j] * 2 + (a[i][j] - y) * (a[i][j] - y) * 2;           if (temp == s) {               ans2 = a[i][j] - y;               break;           }       }       cout << ans1 <<     << ans2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long N = 500005;   long long MAX = 9223372036854775807;   long long MOD = 1000000007;   long double PI = 4 * atan(1);   long long int t, a, b, res;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> t;     while (t--) {       cin >> a >> b;       res = 0;       a = abs(a - b);       res += a / 5;       a = a % 5;       res += a / 2 + a % 2;       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long int T;     cin >> T;     while (T--) {       long long int n;       cin >> n;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       if (a[n - 1] > a[0])         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, siz[200005], l[200005], r[200005], a[200005], p[200005], an = 0,                                                                   b[200005];   bool vis[200005];   vector<int> vt[200005], vec;   set<int> st;   set<int>::iterator it;   int root(int node) {     while (p[node] != node) {       p[node] = p[p[node]];       node = p[node];     }     return node;   }   int merging(int n1, int n2) {     int p1 = root(n1), p2 = root(n2);     if (p1 == 0) return p2;     if (p2 == 200005 - 1) return p1;     if (p1 == p2) return p1;     if (siz[p1] > siz[p2]) {       siz[p1] += siz[p2];       p[p2] = p[p1];       l[p1] = min(l[p1], l[p2]);       r[p1] = max(r[p1], r[p2]);       return p1;     } else {       siz[p2] += siz[p1];       p[p1] = p[p2];       l[p2] = min(l[p2], l[p1]);       r[p2] = max(r[p1], r[p2]);       return p2;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     scanf( %d , &n);     int lef = 1, cur = 1, ri;     st.insert(0);     st.insert(200005 - 1);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (i != 1 && a[i] != a[i - 1]) {         l[cur] = lef, r[cur] = i - 1;         siz[cur] = r[cur] - l[cur] + 1;         vt[siz[cur]].push_back(l[cur]);         p[cur] = cur;         cur++;         lef = i;       }       st.insert(i);       b[i] = cur;     }     l[cur] = lef, r[cur] = n, siz[cur] = n - lef + 1;     vt[siz[cur]].push_back(l[cur]);     p[cur] = cur;     for (int i = 200005 - 1; i >= 1; i--) {       sort(vt[i].begin(), vt[i].end());       for (int j = 0, par, tmp, tpp, lol, now; j < vt[i].size(); j++) {         now = vt[i][j];         if (vis[now]) continue;         par = root(b[now]);         it = st.lower_bound(l[par]);         it--;         tmp = *it;         it = st.lower_bound(r[par]);         it++;         tpp = *it;         if (a[tmp] == a[tpp] && a[tmp]) {           lol = merging(b[tmp], b[tpp]);           if (siz[lol] >= i) {             vt[i][j] = l[lol];             j--;           } else             vt[siz[lol]].push_back(l[lol]);         }         for (it = st.lower_bound(l[par]); *it <= r[par]; it++) vec.push_back(*it);         for (int k = 0; k < vec.size(); k++) {           st.erase(vec[k]), vis[vec[k]] = true;         }         vec.clear();         an++;       }     }     printf( %d n , an);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int maxi = 0;     int ind = 0;     string ret =   ;     for (int i = 0; i < n; i++) {       string temp;       int d = 10 - (s[i] - 48);       int j = i;       int ctr = 0;       while (ctr < n) {         ctr++;         temp += ((s[j] - 48 + d) % 10) + 48;         j = (j + 1) % s.length();       }       if (ret ==   )         ret = temp;       else if (temp < ret)         ret = temp;     }     cout << ret;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long n;     cin >> n;     vector<vector<long long> > p(2, vector<long long>(n)),         suf(2, vector<long long>(n + 1)), ebalVLevo(2, vector<long long>(n + 1)),         ebalVPravo(2, vector<long long>(n + 1));     for (long long i = 0; i < 2; i++) {       for (long long j = 0; j < n; j++) {         cin >> p[i][j];       }     }     for (long long i = 0; i < 2; i++) {       suf[i][n - 1] = p[i][n - 1];       for (long long j = n - 2; j >= 0; j--) {         suf[i][j] = suf[i][j + 1] + p[i][j];       }     }     for (long long i = 0; i < 2; i++) {       ebalVPravo[i][0] = (n)*p[i][0];       for (long long j = 1; j < n; j++) {         ebalVPravo[i][j] = ebalVPravo[i][j - 1] + p[i][j] * (n + j);       }     }     for (long long i = 0; i < 2; i++) {       ebalVLevo[i][n - 1] = p[i][n - 1];       for (long long j = n - 2; j >= 0; j--) {         ebalVLevo[i][j] = ebalVLevo[i][j + 1] + p[i][j] * (n - j);       }     }     long long sum = 0;     long long ans = 0;     long long i = 0, j = 0;     bool lastI = false;     for (long long t = 0; t < 2 * n; t++) {       sum += t * p[i][j];       long long tmp = sum;       long long tmpR =           ebalVPravo[i][n - 1] - ebalVPravo[i][j] - (n - t + j) * suf[i][j + 1];       long long tmpL = 0;       long long tmpLL = 0;       if (t == 0) {         tmpL = ebalVLevo[1][j] + (t + (n - j) - 1) * suf[1][j];       } else if (i == 0) {         tmpL = ebalVLevo[1][j + 1] + (t + (n - j) - 1) * suf[1][j + 1];       } else if (i == 1) {         tmpL = ebalVLevo[0][j + 1] + (t + (n - j) - 1) * suf[0][j + 1];       }       ans = max(ans, tmp + tmpL + tmpR);       if (!lastI) {         if (!i) {           i++;         } else {           i--;         }         lastI = true;       } else {         j++;         lastI = false;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[300005];   vector<long long> g[300005];   long long ans = 1;   long long subs[300005];   long long f[300005][2];   void dfs(long long s, long long p) {     dp[s] = 0;     long long mx1 = 0;     long long mx2 = 0;     long long cnt = 0;     for (auto it : g[s]) {       if (it != p) {         dfs(it, s);         if (mx1 < dp[it]) {           mx2 = mx1;           mx1 = dp[it];         } else if (mx2 < dp[it])           mx2 = dp[it];         cnt++;       }     }     f[s][0] = mx1;     f[s][1] = mx2;     subs[s] = cnt;     dp[s] += mx1 + cnt;   }   void ans_dfs(long long s, long long p) {     for (auto it : g[s]) {       if (it != p) ans_dfs(it, s);     }     if (s == p) {       ans = max(ans, 1 + dp[s] + f[s][1]);       return;     }     long long y = f[p][0];     if (y == dp[s]) y = f[p][1];     long long z = max(y, f[s][1]);     ans = max(ans, 1 + dp[s] + z + 1);   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 1; i <= n; i++) {         dp[i] = 0;         g[i].clear();       }       for (long long i = 0; i < n - 1; i++) {         long long a, b;         cin >> a >> b;         g[a].push_back(b);         g[b].push_back(a);       }       ans = 1;       dfs(1, 1);       ans_dfs(1, 1);       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 18;   long long dp[(1 << N)][105];   string n;   int qwq;   int m, pw[20];   bool used[10];   void init() {     pw[0] = 1;     for (int i = 1; i <= n.size(); i++) pw[i] = pw[i - 1] * 10 % m;   }   int main() {     cin >> n >> m;     dp[0][0] = 1;     init();     for (int i = 1; i < (1 << n.size()); i++) {       int sz = n.size() - __builtin_popcount(i);       for (int k = 0; k < m; k++) {         for (int j = 0; j < 10; j++) used[j] = false;         for (int j = 0; j < n.size(); j++)           if (((i >> j) & 1) && !used[n[j] -  0 ])             if (sz != (int)n.size() - 1 || n[j] !=  0 )               dp[i][k] +=                   dp[i - (1 << j)][(m + k - (n[j] -  0 ) * pw[sz] % m) % m],                   used[n[j] -  0 ] = true;       }     }     cout << dp[(1 << n.size()) - 1][0] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXM = 500 + 5;   const int MAXN = 500 + 5;   const int MAXQ = 300 + 5;   const int MAXK = 800 + 5;   const int P = 5;   const int MOD = 1e9 + 7;   int n, m, q, a[MAXN][MAXK];   int inv[P], ans = 1;   char buf[MAXM];   int main() {     for (int i = 0; i < P; i++) inv[i] = i * i * i % P;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , buf + 1);       for (int j = 1; j <= m; j++) a[j][i] = buf[j] -  a ;     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %s , buf + 1);       for (int j = 1; j <= m; j++) a[j][i + n] = buf[j] -  a ;     }     int cur = 1, r = 0;     for (int i = 1; i <= m && cur <= n; i++) {       while (cur <= n) {         int t = i;         for (int j = i + 1; j <= m; j++)           if (a[j][cur]) t = j;         for (int j = 1; j <= n + q; j++) swap(a[i][j], a[t][j]);         if (a[i][cur]) break;         cur++;       }       if (cur == n + 1) break;       for (int j = cur + 1; j <= n + q; j++)         a[i][j] = a[i][j] * inv[a[i][cur]] % P;       a[i][cur] = 1;       for (int j = i + 1; j <= m; j++) {         for (int k = cur + 1; k <= n + q; k++) {           a[j][k] -= a[j][cur] * a[i][k] % P;           if (a[j][k] < 0) a[j][k] += P;         }         a[j][cur] = 0;       }       r++;     }     for (int i = 1; i <= n - r; i++) ans = ans * 5ll % MOD;     for (int i = 1; i <= q; i++) {       int x = ans;       for (int j = 1; j <= m; j++) {         bool flg = 1;         for (int k = 1; k <= n; k++) flg &= (a[j][k] == 0);         flg &= (a[j][n + i] > 0);         if (flg) x = 0;       }       printf( %d n , x);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> st[100000], edge[200000], topo;   vector<pair<int, int> > ps;   int incnt[200000], tol;   priority_queue<int> que;   bool visit[200000];   int main(void) {     int n, m, in;     while (scanf( %d %d , &n, &m) == 2) {       for (int i = 0; i < m; ++i) st[i].clear();       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) {           scanf( %d , &in);           st[j].push_back(in);         }       memset(incnt, 0, sizeof(incnt));       tol = m;       for (int i = 0; i < 200000; ++i) edge[i].clear();       for (int i = 0; i < n; ++i) {         ps.clear();         for (int j = 0; j < m; ++j)           if (st[j][i] >= 0) ps.push_back(make_pair(st[j][i], j));         sort(ps.begin(), ps.end());         for (int a = 0, b, k = ps.size(), pre = -1; a < k; a = b) {           for (b = a; (b < k) && (ps[b].first == ps[a].first); ++b) {             int now = ps[b].second;             if (pre >= 0) {               edge[pre].push_back(now);               ++incnt[now];             }             edge[now].push_back(tol);             ++incnt[tol];           }           pre = tol++;         }       }       topo.clear();       for (int i = 0; i < tol; ++i)         if (!incnt[i]) que.push(-i);       while (!que.empty()) {         int now = -que.top();         que.pop();         if (now < m) topo.push_back(now + 1);         for (int i = 0, j = edge[now].size(); i < j; ++i) {           --incnt[edge[now][i]];           if (!incnt[edge[now][i]]) que.push(-edge[now][i]);         }       }       if (topo.size() != m)         puts( -1 );       else {         printf( %d , topo[0]);         for (int i = 1, j = topo.size(); i < j; ++i) printf(  %d , topo[i]);         putchar(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   map<int, string> mp_back;   vector<int> way[5005 * 2];   int n, j, i, ans[5005 * 2] = {};   int main() {     cin >> n;     int w = 0;     for (i = 1; i <= n; i++) {       int v1, v2;       string s1, s2;       cin >> s1 >> s2;       if (!mp[s1])         ++w, mp[s1] = w, v1 = w, mp_back[w] = s1;       else         v1 = mp[s1];       if (!mp[s2])         ++w, mp[s2] = w, v2 = w, mp_back[w] = s2;       else         v2 = mp[s2];       way[v1].push_back(v2);       way[v2].push_back(v1);     }     for (i = 1; i <= w; i++) {       int friends[5005 * 2] = {}, friends2[5005 * 2] = {};       for (j = 0; j < way[i].size(); j++) friends[way[i][j]] = 1;       int maxf = 0;       for (j = 1; j <= w; j++)         if (!friends[j] && j != i) {           int size = 0;           for (int h = 0; h < way[j].size(); h++)             if (friends[way[j][h]]) ++size;           maxf = max(maxf, size);           friends2[j] = size;         }       for (j = 1; j <= w; j++)         if (friends2[j] == maxf && !friends[j] && j != i) ans[i]++;     }     cout << w << endl;     for (i = 1; i <= w; i++) cout << mp_back[i] <<     << ans[i] << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( avx2 )   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> ans;     for (int i = 1; i <= 1000; i += 2) {       ans.push_back(i);       ans.push_back(i);     }     if (ans.size() < n) {       for (int i = 0; i < ans.size(); i++) {         cout << ans[i] <<    ;       }       n -= ans.size();       for (int i = 0; i < n; i++) {         cout << ans[i] <<    ;       }       cout << endl;       return;     }     for (int i = int(0); i < int(n); i++) {       cout << ans[i] <<    ;     }     cout << endl;   }   signed main() {     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, i, j, sum, p[3][3];     stack<int> s;     queue<int> q1, q2;     for (i = 0; i < 3; i++)       for (j = 0; j < 3; j++) p[i][j] = (j + 3 - i) % 3;     while (s.size()) s.pop();     while (q1.size()) q1.pop();     while (q2.size()) q2.pop();     scanf( %d%d , &a, &b);     while (a) {       q1.push(a % 3);       a /= 3;     }     while (b) {       q2.push(b % 3);       b /= 3;     }     if (q1.size() > q2.size())       for (i = q2.size(); i < q1.size(); i++) q2.push(0);     else {       if (q2.size() > q1.size())         for (i = q1.size(); i < q2.size(); i++) q1.push(0);     }     while (q1.size()) {       a = q1.front();       q1.pop();       b = q2.front();       q2.pop();       s.push(p[a][b]);     }     sum = 0;     while (s.size()) {       c = s.top();       s.pop();       sum = sum * 3 + c;     }     printf( %d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   const int MOD = 1e9 + 7;   const long long INFLL = 0x3f3f3f3f3f3f3f3f;   const int INF = 0x3f3f3f3f;   const int MAXN = 4e5 + 5;   char s[MAXN];   int vis[200], t[200];   int check(int n, int l) {     int need = (l / 2) * n, cnt = 0;     for (int i = 0; i < 200; i++) cnt += vis[i] / 2;     if (cnt >= need) return 1;     return 0;   }   void solve(int n, int l) {     vector<char> v1, v2;     printf( %d n , n);     for (int i = 0; i < 200; i++) {       while (vis[i] >= 2) v1.push_back((char)i), vis[i] -= 2;       if (vis[i]) v2.push_back((char)i);     }     for (int i = 0; i < n; i++) {       int p = 0;       while (p < l / 2) {         s[p] = s[l - 1 - p] = v1[v1.size() - 1];         v1.pop_back();         p++;       }       if (l & 1) {         if (v2.empty())           s[p] = v1[v1.size() - 1], v2.push_back(v1[v1.size() - 1]),           v1.pop_back();         else           s[p] = v2[v2.size() - 1], v2.pop_back();       }       s[l] = 0;       printf( %s  , s);     }   }   int main() {     int n;     cin >> n;     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) vis[s[i]]++;     int maxn = INF;     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) {         if (check(i, n / i)) maxn = min(i, maxn);         if (check(n / i, i)) maxn = min(n / i, maxn);       }     }     solve(maxn, n / maxn);   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100001];   vector<vector<pair<int, int>>> o[6], ans;   void relax(vector<int>& m) {     o[m.size()].push_back({});     for (size_t i = 0; i < m.size(); i++)       o[m.size()].back().push_back({m[i], m[(i + 1) % m.size()]});     m.resize(1);   }   void gao(int x, int y) {     if (!y) ans.insert(ans.end(), o[x].begin(), o[x].end());     while (o[x].size() > (x == y) && o[y].size()) {       ans.push_back(o[x].back());       o[x].pop_back();       ans.back().insert(ans.back().end(), o[y].back().begin(), o[y].back().end());       o[y].pop_back();     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++)       if (a[i] != i) {         vector<int> u = {i}, m = {i};         while (a[u.back()] != i) u.push_back(a[u.back()]);         for (size_t c = 1; c < u.size(); c++) {           if (m.size() == 5) relax(m);           m.push_back(a[u[c]] = u[c]);         }         relax(m);       }     gao(5, 0);     gao(4, 0);     gao(2, 3);     while (o[3].size() >= 2) {       auto u = o[3].back();       o[3].pop_back();       o[2].push_back({{u[0].first, u[1].first}, {u[1].first, u[0].first}});       o[2].push_back({{u[1].first, u[2].first}, {u[2].first, u[1].first}});       gao(2, 3);     }     gao(2, 2);     gao(3, 0);     gao(2, 0);     printf( %d n , ans.size());     for (auto& c : ans) {       printf( %d n , c.size());       for (auto x : c) printf( %d  , x.first);       puts(  );       for (auto x : c) printf( %d  , x.second);       puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, tot, a[100010], ans[100010];   vector<pair<int, int> > q[100010];   set<int> s;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1, l, x; i <= m; i++) {       scanf( %d%d , &l, &x);       q[l].emplace_back(i, x);     }     s.insert(0);     tot = 1;     for (int i = 1; i <= n; i++) {       if (s.count(a[i]))         tot = 1ll * tot * 2 % 1000000007;       else {         vector<int> v;         for (int u : s) v.push_back(u ^ a[i]);         for (int u : v) s.insert(u);       }       for (auto &p : q[i]) ans[p.first] = s.count(p.second) ? tot : 0;     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     std::cerr << name <<   :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long int solve() {     long long int n;     cin >> n;     std::vector<long long int> v;     long long int seg = 0;     long long int count = 0;     for (long long int i = 0; i < n; i++) {       long long int a;       cin >> a;       v.push_back(a);       if (a != i + 1) {         count++;       } else {         if (count) {           seg++;           count = 0;         }       }     }     if (count) {       seg++;     }     if (seg == 0) {       cout << 0 <<   n ;     } else if (seg == 1) {       cout << 1 <<   n ;     } else {       cout << 2 <<   n ;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int T = 1;     cin >> T;     while (T--) {       solve();     }     return 0;   }