malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, a[200005];   void slove() {     int temp, u, v, w, m;     for (int i = 1; i <= n; i++) cin >> temp, a[i] = 0x3f3f3f3f;     cin >> m;     for (int i = 1; i <= m; i++) {       cin >> u >> v >> w;       if (a[v] > w) a[v] = w;     }     int flag = 1, k = 1;     int ans = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == 0x3f3f3f3f && k) {         ans -= 0x3f3f3f3f;         k = 0;       } else if (a[i] == 0x3f3f3f3f) {         flag = 0;         break;       }       ans += a[i];     }     if (flag)       cout << ans <<   n ;     else       cout << -1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     slove();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (1ll << 60);   const int N = 205;   int n, m, _len;   int nxt[N];   long long k;   long long ADD(long long x, long long y) { return min(INF, x + y); }   struct node {     char pref[N];     char suff[N];     long long len;     long long sum;   } t[N * 4], eddd;   char s[N * 4];   char ans[N];   node operator+(node a, node b) {     node ans;     ans.len = ADD(a.len, b.len);     ans.sum = ADD(a.sum, b.sum);     int l1 = min(a.len, 2ll * _len);     int l2 = min(b.len, 2ll * _len);     for (int i = (int)(1); i <= (int)(min(l1, _len)); i++) s[i] = a.pref[i];     for (int i = (int)(1); i <= (int)(min(l1, _len)); i++)       s[l1 - i + 1] = a.suff[i];     for (int i = (int)(1); i <= (int)(min(l2, _len)); i++) s[l1 + i] = b.pref[i];     for (int i = (int)(1); i <= (int)(min(l2, _len)); i++)       s[l1 + l2 - i + 1] = b.suff[i];     int p = 0;     s[l1 + l2 + 1] = 0;     for (int i = (int)(l1 - min(l1, _len - 1) + 1);          i <= (int)(l1 + 1 + min(l2, _len - 1) - 1); i++) {       for (; p && s[i] != ::ans[p + 1]; p = nxt[p])         ;       if (s[i] == ::ans[p + 1]) ++p;       if (p == _len) ++ans.sum, p = nxt[p];     }     for (int i = (int)(1); i <= (int)(min(_len, l1 + l2)); i++)       ans.pref[i] = s[i];     for (int i = (int)(1); i <= (int)(min(_len, l1 + l2)); i++)       ans.suff[i] = s[l1 + l2 - i + 1];     return ans;   }   long long count(int l) {     _len = l;     nxt[1] = 0;     for (int i = (int)(2); i <= (int)(l); i++) {       int j = nxt[i - 1];       for (; j && ans[j + 1] != ans[i]; j = nxt[j])         ;       nxt[i] = j + (ans[j + 1] == ans[i]);     }     t[0].pref[1] = t[0].suff[1] =  0 ;     t[1].pref[1] = t[1].suff[1] =  1 ;     eddd.pref[1] = eddd.suff[1] =  2 ;     t[0].len = t[1].len = eddd.len = 1;     t[0].sum = (l == 1 && ans[1] ==  0 );     t[1].sum = (l == 1 && ans[1] ==  1 );     eddd.sum = (l == 1 && ans[1] ==  2 );     for (int i = (int)(2); i <= (int)(n); i++) {       t[i] = t[i - 2] + t[i - 1];     }     return (t[n] + eddd).sum;   }   int main() {     scanf( %d%lld%d , &n, &k, &m);     k++;     for (int i = (int)(1); i <= (int)(m); i++) {       ans[i] =  2 ;       long long val = count(i);       if (val >= k) break;       k -= val;       ans[i] =  0 ;       val = count(i);       if (val >= k) {         putchar( 0 );         continue;       }       k -= val;       ans[i] =  1 ;       val = count(i);       if (val >= k) {         putchar( 1 );         continue;       }       assert(0);     }   }
#include <bits/stdc++.h>   using namespace std;   const int B = 27397, MOD = 1e9 + 7;   const int B1 = 33941, MOD1 = 1e9 + 9;   int t;   inline void solve() {     int r, n;     scanf( %d%d , &n, &r);     --r;     int sum = 0;     for (int i = 0; i < n - 1; ++i) {       int x;       scanf( %d , &x);       --x;       sum += x;     }     for (int i = 0; i < n; ++i)       if ((sum + i) % n == r) printf( %d n , i + 1);   }   int main(void) {     scanf( %d , &t);     while (t-- > 0) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, long long> > > g;   int n, a[100005];   bool erased[100005];   void dfs(int cur, long long cost, long long minCost) {     if (cost - minCost > 1ll * a[cur]) {       erased[cur] = 1;       return;     }     for (int i = 0; i < g[cur].size(); i++) {       dfs(g[cur][i].first, cost + g[cur][i].second, min(minCost, cost));     }   }   int count(int u) {     if (erased[u]) return 0;     int ans = 1;     for (int i = 0; i < g[u].size(); i++) ans += count(g[u][i].first);     return ans;   }   int main() {     scanf( %d , &n);     g.assign(n, vector<pair<int, long long> >());     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       int v, c;       scanf( %d %d , &v, &c);       v--;       g[v].push_back(pair<int, long long>(i, c));     }     memset(erased, 0, sizeof erased);     dfs(0, 0ll, 0ll);     printf( %d n , n - count(0));   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int fibo[200005], t[20][200005], f[20][200005], a[1000006], g[200005],       h[200005], s[200005];   void FWT_or(int*, int, int);   void FWT_and(int*, int, int);   void FWT_xor(int*, int, int);   void init();   int main() {     init();     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);       int x = a[i], cnt = 0;       m = max(m, x);       for (int j = 0; j <= 17; ++j)         if (x & (1 << j)) ++cnt;       ++f[cnt][x];       ++h[x];       ++s[x];     }     int bit = 1, l = 1;     while (bit <= m) bit <<= 1, ++l;     for (int i = 0; i <= l; ++i) FWT_or(f[i], 1, bit);     for (int i = 1; i <= l; ++i)       for (int j = 0; j <= i; ++j)         for (int k = 0; k < bit; ++k)           t[i][k] = (1ll * t[i][k] + 1ll * f[j][k] * f[i - j][k] % 1000000007) %                     1000000007;     for (int i = 0; i <= l; ++i) {       FWT_or(t[i], -1, bit);       for (int j = 0; j < bit; ++j) {         int cnt = 0;         for (int k = 0; k <= l; ++k)           if (j & (1 << k)) ++cnt;         g[j] = (1ll * g[j] + t[i][j] * (cnt == i)) % 1000000007;       }     }     FWT_xor(h, 1, bit);     for (int i = 0; i < bit; ++i) h[i] = 1ll * h[i] * h[i] % 1000000007;     FWT_xor(h, -1, bit);     for (int i = 0; i < bit; ++i)       s[i] = 1ll * fibo[i] * s[i] % 1000000007,       g[i] = 1ll * fibo[i] * g[i] % 1000000007,       h[i] = 1ll * fibo[i] * h[i] % 1000000007;     FWT_and(h, 1, bit);     FWT_and(g, 1, bit);     FWT_and(s, 1, bit);     for (int i = 0; i < bit; ++i)       s[i] = 1ll * s[i] * g[i] % 1000000007 * h[i] % 1000000007;     FWT_and(s, -1, bit);     int ans = 0;     for (int i = 1; i < bit; i <<= 1) ans = (1ll * ans + s[i]) % 1000000007;     cout << ans << endl;     return 0;   }   void FWT_or(int* x, int f, int len) {     for (int i = 1; i < len; i <<= 1)       for (int j = 0; j < len; j += i << 1)         for (int k = 0; k < i; ++k)           x[i + j + k] =               (1ll * x[i + j + k] + x[j + k] * f + 1000000007) % 1000000007;     return;   }   void FWT_and(int* x, int f, int len) {     for (int i = 1; i < len; i <<= 1)       for (int j = 0; j < len; j += i << 1)         for (int k = 0; k < i; ++k)           x[j + k] =               (1ll * x[j + k] + x[i + j + k] * f + 1000000007) % 1000000007;     return;   }   void FWT_xor(int* x, int f, int len) {     for (int i = 1; i < len; i <<= 1)       for (int j = 0; j < len; j += i << 1)         for (int k = 0; k < i; ++k) {           int p = x[j + k], q = x[i + j + k];           x[j + k] = (1ll * p + q) % 1000000007;           x[i + j + k] = (1ll * p - q + 1000000007) % 1000000007;           if (f == -1)             x[j + k] = 1ll * x[j + k] * 500000004 % 1000000007,                   x[i + j + k] = 1ll * x[i + j + k] * 500000004 % 1000000007;         }     return;   }   void init() {     fibo[1] = fibo[2] = 1;     for (int i = 3; i <= (1 << 17); ++i)       fibo[i] = (1ll * fibo[i - 1] + fibo[i - 2]) % 1000000007;     return;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 1e5 + 10;   long long power(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret *= a;       a *= a;       if (ret >= MOD) ret %= MOD;       if (a >= MOD) a %= MOD;       b >>= 1;     }     return ret;   }   long long invmod(long long x) { return power(x, MOD - 2); }   long long dp[55][2];   long long a[55];   long long n;   long long go(long long pos, long long check) {     if (pos == n + 1) return 0;     if (dp[pos][check] != -1) return dp[pos][check];     long long ans = 0;     if (check == 0) {       ans += max(a[pos] + go(pos + 1, check ^ 1), go(pos + 1, check));     } else {       ans += min(go(pos + 1, check ^ 1), a[pos] + go(pos + 1, check));     }     dp[pos][check] = ans;     return ans;   }   int32_t main() {     cin >> n;     long long sum = 0;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     memset(dp, -1, sizeof(dp));     long long k = go(1, 0);     cout << sum - k <<     << k << endl;   }
#include <bits/stdc++.h>   template <typename T>   inline bool MIN(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool MAX(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   using namespace std;   int n, m, K, p;   int exgcd(int a, int b, int &x, int &y) {     if (b == 0) {       x = 1, y = 0;       return a;     }     int res = exgcd(b, a % b, x, y);     int t = x;     x = y;     y = t - a / b * y;     return res;   }   int get_inv(int a) {     int x, y;     exgcd(a, 1000000007, x, y);     return (x % 1000000007 + 1000000007) % 1000000007;   }   int P[100010], sum_P[100010];   int g[1510][1510], sum[1510][1510];   int main() {     scanf( %d%d , &n, &m);     int a, b;     scanf( %d%d , &a, &b);     p = (long long)a * get_inv(b) % 1000000007;     scanf( %d , &K);     int pow2 = 1;     for (int i = 1; i <= K; ++i)       pow2 = (long long)pow2 * (1 - p + 1000000007) % 1000000007;     for (int i = 0, pow = 1, c = 1; i <= K; ++i) {       if (i == K && p == 1) pow2 = 1;       P[i] = (long long)c * pow % 1000000007 * pow2 % 1000000007;       pow2 = (long long)pow2 * get_inv((1 - p + 1000000007) % 1000000007) %              1000000007;       pow = (long long)pow * p % 1000000007;       c = (long long)c * (K - i) % 1000000007 * get_inv(i + 1) % 1000000007;     }     sum_P[0] = P[0];     for (int i = 1; i <= m; ++i) sum_P[i] = (sum_P[i - 1] + P[i]) % 1000000007;     g[0][m] = sum[0][m] = 1;     for (int i = 1; i <= n; ++i) {       int tmp = 0;       for (int j = 1; j <= m; ++j) {         tmp = (tmp + (long long)P[j - 1] * sum[i - 1][j - 1]) % 1000000007;         g[i][j] = ((long long)sum_P[j - 1] *                        (sum[i - 1][m] - sum[i - 1][m - j] + 1000000007) -                    tmp + 1000000007) %                   1000000007;         g[i][j] = (long long)g[i][j] * P[m - j] % 1000000007;         sum[i][j] = (sum[i][j - 1] + g[i][j]) % 1000000007;       }     }     printf( %d n , sum[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long m, n, b[12345], w[12345], u, v, d = 0, c = 0;     int mx = INT_MIN, mn = INT_MAX;     string p[123];     char ch;     bool sorted;     cin >> n >> m;     vector<int> a(n);     for (int row = 0; row < n; row++) {       cin >> p[row];       for (int col = 0; col < m; col++) {         if (p[row][col] ==  * ) {           c = c ^ row;           d = d ^ col;         }       }     }     cout << c + 1 <<     << d + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int top = 0;   int N, Q, NN;   int K, M, R;   vector<int> Adj[100005];   int dep[100005];   int anc[100005][21];   int pre[100005], pst[100005], tt;   void dfs(int u) {     pre[u] = ++tt;     for (int j = 1; j <= 20; j++) {       if (dep[u] <= (1 << j)) break;       anc[u][j] = anc[anc[u][j - 1]][j - 1];     }     int v;     for (int k = 0; k < Adj[u].size(); k++) {       v = Adj[u][k];       if (v == anc[u][0]) continue;       anc[v][0] = u;       dep[v] = dep[u] + 1;       dfs(v);     }     pst[u] = ++tt;   }   int lca(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     for (int j = 20; j >= 0; j--) {       if (dep[anc[u][j]] >= dep[v]) {         u = anc[u][j];       }     }     if (u == v) return u;     for (int j = 20; j >= 0; j--) {       if (anc[u][j] != anc[v][j]) {         u = anc[u][j];         v = anc[v][j];       }     }     return anc[u][0];   }   int h[100005], c[2 * 100005];   int lbt(int x) { return x & (-x); }   void update(int x, int dv) {     for (; x <= NN; x += lbt(x)) {       c[x] += dv;     }   }   int getsum(int x) {     int ans = 0;     for (; x > 0; x -= lbt(x)) {       ans += c[x];     }     return ans;   }   bool cmp(const int& a, const int& b) { return dep[a] < dep[b]; }   int query(int u, int lca) { return getsum(pre[u] - 1) - getsum(pre[lca] - 1); }   int a[100005];   bool vis[100005];   long long dp[100005][305];   int work() {     int u, z;     for (int i = 1; i <= K; i++) {       u = a[i];       update(pre[u], 1);       update(pst[u], -1);       vis[a[i]] = 1;     }     int x;     for (int i = 1; i <= K; i++) {       u = a[i];       z = lca(u, R);       if (u == R)         h[i] = 0;       else if (u == z)         h[i] = query(R, u) - (vis[u] == true) + (vis[R] == true);       else if (z == R)         h[i] = query(u, R);       else         h[i] = query(u, z) + query(R, z) - (vis[z] == true) + (vis[R] == true);     }     sort(h + 1, h + 1 + K);     dp[1][1] = 1;     for (int i = 2; i <= K; i++) {       for (int j = 1; j <= M; j++) {         if (j > h[i])           dp[i][j] = ((long long)dp[i - 1][j] * (j - h[i]) % int(1e9 + 7) +                       dp[i - 1][j - 1]) %                      int(1e9 + 7);         else           dp[i][j] = 0;       }     }     long long ans = 0;     for (int j = 1; j <= M; j++) {       ans = (ans + dp[K][j]) % int(1e9 + 7);     }     for (int i = 1; i <= K; i++) {       u = a[i];       update(pre[u], -1);       update(pst[u], +1);       vis[a[i]] = 0;     }     return ans;   }   int main() {     scanf( %d%d , &N, &Q);     int u, v;     for (int i = 1; i < N; i++) {       scanf( %d%d , &u, &v);       Adj[u].push_back(v);       Adj[v].push_back(u);     }     dep[1] = 1;     dfs(1);     NN = 2 * N;     while (Q--) {       scanf( %d%d%d , &K, &M, &R);       for (int i = 1; i <= K; i++) {         scanf( %d , &a[i]);       }       printf( %d n , work());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, k, a[100007];   pair<long long int, long long int> cur[1007];   bool res[200001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (long long int i = 1; i <= n; ++i) cin >> a[i];     long long int last = 0, cnt = 0;     for (long long int t = 0; t <= 150000; ++t) {       for (long long int i = 1; i <= k; ++i) {         if (a[cur[i].second] == cur[i].first) {           if (cur[i].second <= n && cur[i].second >= 1) cnt++;           cur[i].second = ++last;           cur[i].first = 0;         }       }       long long int d = round((100.0 * cnt) / (1.0 * n));       for (long long int i = 1; i <= k; ++i) {         if (cur[i].second <= n && cur[i].second >= 1 && cur[i].first + 1 == d)           res[cur[i].second] = 1;         cur[i].first++;       }     }     long long int sum = 0;     for (long long int i = 1; i <= n; ++i) sum += res[i];     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int s, x1, x2;     cin >> s >> x1 >> x2;     int t1, t2;     cin >> t1 >> t2;     int time_for_igor = abs(x1 - x2) * t2;     int p, d;     cin >> p >> d;     int time_for_tram = -1;     if (x2 > x1) {       if (d == 1) {         if (p > x1) {           time_for_tram = s - p;           time_for_tram += s;           time_for_tram += x1;           time_for_tram += (x2 - x1);           time_for_tram *= t1;         } else {           time_for_tram = abs(x1 - p) * t1;           time_for_tram += abs(x1 - x2) * t1;         }       } else {         time_for_tram = p;         time_for_tram += x1;         time_for_tram += (x2 - x1);         time_for_tram *= t1;       }     } else {       if (d == -1) {         if (p < x1) {           time_for_tram = p;           time_for_tram += s;           time_for_tram += (s - x1);           time_for_tram += (x1 - x2);           time_for_tram *= t1;         } else {           time_for_tram = p - x1;           time_for_tram += x1 - x2;           time_for_tram *= t1;         }       } else {         time_for_tram = s - p;         time_for_tram += s - x1;         time_for_tram += x1 - x2;         time_for_tram *= t1;       }     }     cout << min(time_for_tram, time_for_igor) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   bool f[N][N];   int x[3005], y[3005];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x[i] >> y[i];       f[x[i] + 1000][y[i] + 1000] = true;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if ((x[i] + x[j]) % 2 != 0 || (y[i] + y[j]) % 2 != 0) continue;         int x_md = (x[i] + x[j]) / 2;         int y_md = (y[i] + y[j]) / 2;         if (f[x_md + 1000][y_md + 1000] == 1) ans++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     float num;     int t, n, d;     cin >> num >> t >> n >> d;     int a = (num / n);     if ((num / n) > a) a += 1;     int y = d, x = 0;     for (int i = 0; i < a; i++) {       if (x <= y)         x += t;       else         y += t;     }     if (max(x, y) < (t * a))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 14;   int a[MAX_N];   void add(int st, int x) {     for (int i = 0; i < MAX_N; i++) a[i] += x / MAX_N;     for (int i = 1; i <= abs(x % MAX_N); i++)       a[(st + i) % MAX_N] += (x < 0 ? -1 : 1);   }   long long point() {     long long ans = 0;     for (int i = 0; i < MAX_N; i++)       if (a[i] % 2 == 0) ans += a[i];     return ans;   }   long long move(int st) {     int x = a[st];     a[st] = 0, add(st, x);     long long ans = point();     add(st, -x), a[st] = x;     return ans;   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     for (int i = 0; i < MAX_N; i++) cin >> a[i];     long long ans = 0;     for (int i = 0; i < MAX_N; i++) ans = max(ans, move(i));     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isNonDegenerateTriangle(int a, int b, int c) {     return (a + b > c && b + c > a && c + a > b);   }   bool isDegenerateTriangle(int a, int b, int c) {     return (a + b == c || b + c == a || c + a == b);   }   int main() {     int n;     cin >> n;     long long int a[n], s = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       s += a[i];     }     sort(a, a + n);     cout << 2 * a[n - 1] - s + 1;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, tmp;   long long A[1005];   long long B[1005];   long long Acost(int q) {     q *= 4;     long long ret = 0;     for (int i = 1; i <= n; i++) {       long long tmp2 = i * 4 - 2 - q;       ret += A[i] * tmp2 * tmp2;     }     return ret;   }   long long Bcost(int q) {     q *= 4;     long long ret = 0;     for (int i = 1; i <= m; i++) {       long long tmp2 = i * 4 - 2 - q;       ret += B[i] * tmp2 * tmp2;     }     return ret;   }   int ansx, ansy;   long long sumx = LLONG_MAX, sumy = LLONG_MAX;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> tmp;         A[i] += tmp;         B[j] += tmp;       }     }     for (int i = 0; i <= n; i++) {       long long tmp3 = Acost(i);       if (tmp3 < sumx) {         ansx = i;         sumx = tmp3;       }     }     for (int i = 0; i <= m; i++) {       long long tmp3 = Bcost(i);       if (tmp3 < sumy) {         ansy = i;         sumy = tmp3;       }     }     cout << sumx + sumy << endl;     cout << ansx <<     << ansy << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1005;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long rand(long long a, long long b) {     return uniform_int_distribution<long long>(a, b)(rng);   }   const int K = 3;   struct Hash {     long long a[K];     Hash() : a() {}     Hash operator^(const Hash &A) const {       Hash ans = Hash();       for (int i = 0; i < K; i++) ans.a[i] = a[i] ^ A.a[i];       return ans;     }     bool operator==(const Hash &A) const {       for (int i = 0; i < K; i++)         if (a[i] != A.a[i]) return false;       return true;     }     bool operator<(const Hash &A) const {       for (int i = 0; i < K; i++)         if (a[i] != A.a[i]) return a[i] < A.a[i];       return false;     }   };   Hash genHash() {     Hash ret = Hash();     for (int i = 0; i < K; i++) ret.a[i] = rand(1, 1LL << 60);     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, s, d;     cin >> n >> s >> d;     Hash hash[n], sw[s];     for (int i = 0; i < n; i++) hash[i] = genHash();     for (int i = 0; i < s; i++) {       int k;       cin >> k;       Hash cur = Hash();       while (k--) {         int x;         cin >> x;         cur = cur ^ hash[x - 1];       }       sw[i] = cur;     }     map<Hash, int> left_sz;     int left = min(s / 2, 13);     for (int mask = 0; mask < (1 << left); mask++) {       Hash cur = Hash();       for (int bit = 0; bit < left; bit++) {         if (!((mask >> bit) & 1)) continue;         cur = cur ^ sw[bit];       }       if (!left_sz.count(cur))         left_sz[cur] = __builtin_popcountll(mask);       else         left_sz[cur] = min(left_sz[cur], __builtin_popcountll(mask));     }     map<Hash, int> right_sz;     int right = s - left;     for (int mask = 0; mask < (1 << right); mask++) {       Hash cur = Hash();       for (int bit = 0; bit < right; bit++) {         if (!((mask >> bit) & 1)) continue;         cur = cur ^ sw[bit + left];       }       if (!right_sz.count(cur))         right_sz[cur] = __builtin_popcountll(mask);       else         right_sz[cur] = min(right_sz[cur], __builtin_popcountll(mask));     }     while (d--) {       Hash cur = Hash();       int sz;       cin >> sz;       for (int i = 0; i < sz; i++) {         int x;         cin >> x;         cur = cur ^ hash[x - 1];       }       int ans = 100;       for (auto p : left_sz) {         Hash tmp = cur ^ p.first;         if (right_sz.count(tmp)) ans = min(ans, p.second + right_sz[tmp]);         if (left_sz.count(tmp)) {           if (tmp == p.first)             ans = 0;           else             ans = min(ans, p.second + left_sz[tmp]);         }       }       cout << (ans == 100 ? -1 : ans) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 210;   int n;   int a[N];   bool vis[N];   int lp[N];   int dis[N];   int inloop(int v) {     vis[v] = 1;     int u = a[v];     int cnt = 1;     while (u != v && !vis[u]) {       vis[u] = 1;       ++cnt;       u = a[u];     }     if (u == v) return cnt;     return 0;   }   int dfsandsetlp(int v) {     if (lp[v] > 0) return dis[v];     int t = dfsandsetlp(a[v]);     lp[v] = lp[a[v]];     return dis[v] = t + 1;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     return a / gcd(a, b) * b;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);     }     for (int i = 1; i <= n; ++i) {       memset(vis, 0, sizeof(vis));       int t = inloop(i);       lp[i] = t;     }     for (int i = 1; i <= n; ++i) {       if (!lp[i]) {         dis[i] = dfsandsetlp(i);       }     }     long long res = 1;     for (int i = 1; i <= n; ++i) {       res = lcm(res, lp[i]);     }     int mx = 0;     for (int i = 1; i <= n; ++i) {       mx = max(mx, dis[i]);     }     if (res < mx) {       int t = mx / res;       if (res * t == mx) {         res = mx;       } else {         res = res * (t + 1);       }     }     printf( %I64d n , res);     return 0;   }