malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 20;   struct edge {     int v, l, r;     edge() {}     edge(int a, int b, int c) {       v = a;       l = b;       r = c;     }   };   struct nd {     int no, lim, to;     nd() {}     nd(int a, int b, int c) {       no = a;       lim = b;       to = c;     }   };   bool operator<(const nd& a, const nd& b) {     if (a.no != b.no) {       return a.no > b.no;     }     if (a.lim != b.lim) {       return a.lim > b.lim;     }     return a.to < b.to;   }   bool operator<(const edge& a, const edge& b) {     if (a.l != b.l) {       return a.l < b.l;     }     return a.r < b.r;   }   vector<edge> G[2 * maxn];   int now[2 * maxn];   int main() {     int n, m, u, v, l, r;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d%d%d , &u, &v, &l, &r);       if (l & 1) {         if (r & 1) {           G[u].push_back(edge(v + n, l + 1, r - 1));           G[v].push_back(edge(u + n, l + 1, r - 1));           G[u + n].push_back(edge(v, l, r - 2));           G[v + n].push_back(edge(u, l, r - 2));         } else {           if (l + 1 < r) {             G[u].push_back(edge(v + n, l + 1, r - 2));             G[v].push_back(edge(u + n, l + 1, r - 2));           }           G[u + n].push_back(edge(v, l, r - 1));           G[v + n].push_back(edge(u, l, r - 1));         }       } else {         if (r & 1) {           G[u].push_back(edge(v + n, l, r - 1));           G[v].push_back(edge(u + n, l, r - 1));           if (l + 1 < r) {             G[u + n].push_back(edge(v, l + 1, r - 2));             G[v + n].push_back(edge(u, l + 1, r - 2));           }         } else {           G[u].push_back(edge(v + n, l, r - 2));           G[v].push_back(edge(u + n, l, r - 2));           G[u + n].push_back(edge(v, l + 1, r - 1));           G[v + n].push_back(edge(u, l + 1, r - 1));         }       }     }     for (int i = 1; i <= n + n; i++) {       sort(G[i].begin(), G[i].end());     }     priority_queue<nd> Q;     Q.push(nd(0, 0, 1));     int ans = 0x3f3f3f3f;     nd t;     while (!Q.empty()) {       t = Q.top();       int u = t.to, no = t.no, lim = t.lim;       Q.pop();       if (u == n || u == n * 2) {         ans = min(ans, no);       }       for (int& i = now[u]; i < G[u].size(); i++) {         if (lim < G[u][i].l) {           break;         }         if (no <= G[u][i].r) {           Q.push(nd(max(no + 1, G[u][i].l + 1), G[u][i].r + 1, G[u][i].v));         }       }     }     if (ans == 0x3f3f3f3f) {       printf( -1 n );     } else {       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000008;   int n, m, k, d, i, j, e;   int tmp[N], pos[N], p[N], c[N];   char s[N];   int main() {     scanf( %s %d , s, &m);     n = strlen(s);     while (m--) {       scanf( %d%d , &k, &d);       for (i = 0; i < n; i++) {         c[i] = (i + 1) % n;         pos[i] = p[i] = i;       }       int t = 0;       for (i = 0; i < d; i++)         for (j = i; j < k; t++, j += d) p[t] = j;       for (i = 0; i < n; ++i) {         c[i] = p[c[i]];       }       for (e = n - k + 1; e; e >>= 1) {         for (i = 0; i < n; ++i) tmp[i] = c[i];         if (e & 1)           for (i = 0; i < n; ++i) pos[i] = c[pos[i]];         for (i = 0; i < n; ++i) c[i] = tmp[c[i]];       }       for (i = 0; i < n; ++i) tmp[(i + n - k + 1) % n] = s[pos[i]];       for (i = 0; i < n; ++i) putchar(s[i] = (char)tmp[i]);       putchar(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> ke[1000010];   bool cx[1000010], visited[1000010];   void dfs(int u) {     visited[u] = true;     for (int v : ke[u])       if (!visited[v]) dfs(v);   }   long long c2(int x) { return (1LL * x * (x - 1)) >> 1; }   int main() {     if (fopen( a.txt ,  r )) {       freopen( a.txt ,  r , stdin);     } else       ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     int own = 0;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       cx[u] = true;       cx[v] = true;       if (u != v) {         ke[u].push_back(v);         ke[v].push_back(u);       } else         own++;     }     int cnt = 0;     for (int u = 1; u <= n; u++)       if (cx[u] && !visited[u]) {         dfs(u);         cnt++;       }     if (cnt != 1) {       cout << 0;       exit(0);     };     long long res = 0;     for (int i = 1; i <= n; i++) res += c2(int(ke[i].size()));     res += c2(own);     res += 1LL * own * (m - own);     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   int get_point(int N) {     int score[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};     if (N > 10) return 0;     return score[N - 1];   }   int main() {     int T;     map<string, int> n_map;     map<string, string> n_win;     cin >> T;     for (int i = 0; i < (T); ++i) {       int N;       cin >> N;       for (int j = 0; j < (N); ++j) {         string t_s;         cin >> t_s;         n_map[t_s] += get_point(j + 1);         if (n_win[t_s] ==   )           n_win[t_s] =  0000000000000000000000000000000000000000000000000000 ;         n_win[t_s][j] += 1;       }     }     map<string, int>::iterator it;     int n_max1 = 0, n_max2 = 0;     string n_ret1 =   , n_ret2 =   ;     n_win[  ] =  0000000000000000000000000000000000000000000000000000 ;     for (it = n_map.begin(); it != n_map.end(); it++) {       if (n_max1 < (*it).second) {         n_ret1 = (*it).first;         n_max1 = (*it).second;       }       if (n_max1 == (*it).second && n_win[n_ret1] < n_win[(*it).first]) {         n_ret1 = (*it).first;         n_max1 = (*it).second;       }       if (n_win[n_ret2][0] < n_win[(*it).first][0]) {         n_ret2 = (*it).first;         n_max2 = (*it).second;       }       if (n_win[n_ret2][0] == n_win[(*it).first][0] && n_max2 < (*it).second) {         n_ret2 = (*it).first;         n_max2 = (*it).second;       }       if (n_win[n_ret2][0] == n_win[(*it).first][0] && n_max2 == (*it).second) {         if (n_win[n_ret2] < n_win[(*it).first]) {           n_ret2 = (*it).first;           n_max2 = (*it).second;         }       }     }     cout << n_ret1 << endl;     cout << n_ret2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int n, m, ans, two, one, l, r, k, a[N], dp[N][205];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i] /= 100;     }     memset(dp, 127, sizeof(dp));     dp[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= 200; j++)         if (dp[i][j] <= 2e8) {           if (j + a[i + 1] / 10 <= 200)             dp[i + 1][j + a[i + 1] / 10] =                 min(dp[i + 1][j + a[i + 1] / 10], dp[i][j] + a[i + 1]);           if (j >= a[i + 1])             dp[i + 1][j - a[i + 1]] = min(dp[i + 1][j - a[i + 1]], dp[i][j]);           else             dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + (a[i + 1] - j));         }     }     int ans = 2e9;     for (int i = 0; i <= 200; i++) {       ans = min(ans, dp[n][i]);     }     printf( %d00 n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 40;   const int F = N / 2 + N % 2;   const int S = N - F;   const long long N_MASKS = (1ll << N);   const long long F_MASKS = (1ll << F);   const long long S_MASKS = (1ll << S);   double liquid;   int n, f, s;   long long adj[N];   int firstSizes[F_MASKS];   long long firstAvailables[F_MASKS];   int secondSizes[S_MASKS];   long long secondAvailables[S_MASKS];   int maxPossible[S_MASKS];   void readData() {     cin >> n >> liquid;     f = n / 2 + n % 2;     s = n - f;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         long long a;         cin >> a;         adj[i] |= (a << j);       }     }   }   void findCliques(int sta, int cur, int fin, long long mask, int size,                    long long available, int* sizes, long long* availables) {     if (cur == fin) {       return;     }     findCliques(sta, cur + 1, fin, mask, size, available, sizes, availables);     if ((1ll << cur) & available) {       mask |= (1ll << cur);       ++size;       available &= adj[cur];       sizes[mask >> sta] = size;       availables[mask >> sta] = available;       findCliques(sta, cur + 1, fin, mask, size, available, sizes, availables);     }   }   int findPossibles(long long available) {     if (maxPossible[available]) {       return maxPossible[available];     }     if (available == 0) {       return 0;     }     if (secondSizes[available]) {       return maxPossible[available] = secondSizes[available];     }     for (int i = 0; i < s; ++i) {       if (available & (1ll << i)) {         maxPossible[available] =             max(maxPossible[available], findPossibles(available & ~(1ll << i)));       }     }     return maxPossible[available];   }   int findMaxClique() {     findCliques(0, 0, f, 0, 0, (1ll << n) - 1, firstSizes, firstAvailables);     findCliques(f, f, n, 0, 0, (1ll << n) - 1, secondSizes, secondAvailables);     int res = findPossibles((1 << s) - 1);     for (int mask = 0; mask < (1 << f); ++mask) {       if (firstSizes[mask]) {         res = max(res,                   firstSizes[mask] + findPossibles(firstAvailables[mask] >> f));       }     }     return res;   }   double solve() {     int x = findMaxClique();     return 0.5 * liquid * liquid * (x - 1.) / x;   }   int main() {     ios_base::sync_with_stdio(false);     cout << setprecision(20) << fixed;     readData();     cout << solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2) res = (res * a) % 5;       b = b >> 1;       a = (a * a) % 5;     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long i, n, t;     cin >> n >> t;     long long ans = 1e16;     pair<long long, long long> p;     for (i = 0; i < t; i++) {       long long a, b;       cin >> a >> b;       if (b - a + 1 < ans) {         ans = b - a + 1;       }     }     cout << ans <<   n ;     long long c = 0;     for (i = 0; i < n; i++) {       if (i % ans == 0) {         c = 0;         cout << c <<    ;         c++;       } else {         cout << c <<    ;         c++;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   vector<int> lk[maxn];   int fa[maxn], dep[maxn], a[maxn], b[maxn], n;   void dfs(int now, int pre) {     fa[now] = pre;     dep[now] = dep[pre] + 1;     for (auto p : lk[now])       if (p != pre) dfs(p, now);   }   vector<int> cir;   int rt, lp, lq;   bool find_circle() {     cir.clear();     static bool vis[maxn];     int p = 0;     for (int i = 1; i <= n; i++)       if (a[i] != b[i] && dep[i] > dep[p]) p = i;     if (!p) return 1;     for (int u = p; vis[u] = 1, cir.push_back(u), a[fa[u]] != b[fa[u]]; u = fa[u])       ;     int q = 0;     for (int i = 1; i <= n; i++)       if (a[i] != b[i] && !vis[i] && dep[i] > dep[q]) q = i;     if (q) {       reverse(cir.begin(), cir.end());       for (int u = q; vis[u] = 1, cir.push_back(u), a[fa[u]] != b[fa[u]];            u = fa[u])         ;     } else       q = fa[cir.back()];     for (int i = 1; i <= n; i++)       if (a[i] != b[i] && !vis[i]) return 0;     int u, v;     for (u = p, v = q; u != v; u = fa[u])       if (dep[u] < dep[v]) swap(u, v);     rt = u;     if (cir.size() != dep[p] + dep[q] - 2 * dep[rt]) return 0;     lp = p, lq = q;     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 1, u, v; i < n; i++) {       scanf( %d%d , &u, &v);       lk[u].push_back(v), lk[v].push_back(u);     }     int pa = find(a + 1, a + n + 1, 0) - a, pb = find(b + 1, b + n + 1, 0) - b;     dep[0] = -1;     dfs(pb, 0);     for (int u = pa; u != pb; u = fa[u]) swap(a[u], a[fa[u]]);     long long ans = dep[pa];     if (!find_circle()) {       printf( -1 n );       return 0;     }     if (!cir.size()) {       printf( 0 %d n , ans);       return 0;     }     int gap = 0, len = cir.size();     for (int i = 0; i < len; i++)       if (b[cir[i]] == a[cir[0]]) gap = i;     for (int i = 1; i < len; i++)       if (b[cir[(i + gap) % len]] != a[cir[i]]) {         printf( -1 n );         return 0;       }     static bool vis[maxn];     for (int i = pa; i; i = fa[i]) vis[i] = 1;     if (vis[cir[0]] || vis[cir.back()]) {       if (vis[cir.back()]) reverse(cir.begin(), cir.end()), gap = len - gap;       int po = cir.size();       for (int i = 0; i < cir.size(); i++)         if (!vis[cir[i]]) {           po = i;           break;         }       ans = ans - po +             min(po + gap * 1ll * (len + 1),                 abs((len - gap) * 1ll * (len + 1) - po));     } else       ans = (ans + min(gap, len - gap) * 1ll * (len + 1));     for (; !vis[rt]; rt = fa[rt]) ans += 2;     if (lp > lq) swap(lq, lp);     printf( %d %d %lld n , lp, lq, ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   struct Edge {     int v, u, f, r, c;     Edge() {}     Edge(int v, int u, int f, int c, int r) : v(v), u(u), f(f), c(c), r(r) {}   };   const int inf = 1e9;   const int C = 4000;   int n, m, k, nflow, s, t, parent[N], number[N], a[N], b[N];   int dist[N], pl[N];   vector<Edge> g[N];   queue<pair<int, int> > q;   vector<int> ga, gb;   void addEdge(int a, int b, int u, int c) {     g[a].push_back(Edge(b, u, 0, c, g[b].size()));     g[b].push_back(Edge(a, 0, 0, -c, g[a].size() - 1));   }   int MinCostFlow() {     int flow = 0;     int cost = 0;     while (true) {       for (int i = 1; i <= nflow; i++) dist[i] = inf;       dist[s] = 0;       q.push(make_pair(0, s));       while (!q.empty()) {         int v = (q.front()).second;         int d = -(q.front()).first;         q.pop();         if (dist[v] != d) continue;         if (d == inf) break;         for (int i = 0; i < g[v].size(); i++)           if (g[v][i].f < g[v][i].u && dist[g[v][i].v] > d + g[v][i].c) {             dist[g[v][i].v] = d + g[v][i].c;             q.push(make_pair(-dist[g[v][i].v], g[v][i].v));             number[g[v][i].v] = i;             parent[g[v][i].v] = v;           }       }       if (dist[t] == inf) break;       int v = t, addflow = 1e9;       while (v != s) {         int u = parent[v];         addflow = min(addflow, g[u][number[v]].u - g[u][number[v]].f);         v = u;       }       v = t;       while (v != s) {         int u = parent[v];         cost += addflow * g[u][number[v]].c;         g[u][number[v]].f += addflow;         g[v][g[u][number[v]].r].f -= addflow;         v = u;       }       flow += addflow;     }     return cost;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     s = n + 3;     t = n + 4;     for (int i = 1; i <= n; i++) {       addEdge(n + 1, i, 1, -a[i]);       addEdge(n + 2, i, 1, -b[i]);     }     addEdge(s, n + 1, m, 0);     addEdge(s, n + 2, k, 0);     for (int i = 1; i <= n; i++) {       addEdge(i, t, 1, 0);     }     nflow = n + 4;     int ans = -MinCostFlow();     cout << ans << endl;     for (int j = 0; j < g[n + 1].size(); j++) {       int v = g[n + 1][j].v;       if (v >= 1 && v <= n && g[n + 1][j].f == 1) {         ga.push_back(v);       }     }     for (int j = 0; j < g[n + 2].size(); j++) {       int v = g[n + 2][j].v;       if (v >= 1 && v <= n && g[n + 2][j].f == 1) {         gb.push_back(v);       }     }     for (int i = 0; i < ga.size(); i++) cout << ga[i] <<    ;     cout << endl;     for (int i = 0; i < gb.size(); i++) cout << gb[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n;   double a[N];   double max_poor(double x) {     int i;     double pre, mpre, ret = 0;     pre = mpre = 0;     for (i = 0; i < n; i++) {       pre += a[i] - x;       ret = max(ret, abs(pre - mpre));       mpre = min(mpre, pre);     }     pre = mpre = 0;     for (i = 0; i < n; i++) {       pre += a[i] - x;       ret = max(ret, abs(pre - mpre));       mpre = max(mpre, pre);     }     return ret;   }   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     int i;     double l = 0.0, h = 0.0, m1, m2;     cin >> n;     for (i = 0; i < n; h = max(h, abs(a[i])), i++) cin >> a[i];     l = -h;     for (i = 0; i < 300; i++) {       m1 = l + (h - l) / 3;       m2 = h - (h - l) / 3;       if (max_poor(m1) > max_poor(m2))         l = m1;       else         h = m2;     }     printf( %.17f n , max_poor(l));     return 0;   }
#include <bits/stdc++.h>   const long long MOD = 1000000007;   const int MAX = 1e9 + 7;   const int MIN = -1e9 + 7;   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long b, g;     cin >> b >> g;     long long n;     cin >> n;     if (b >= n && g >= n) {       cout << n + 1;     } else if (b + g == n) {       cout << 1;     } else if (b >= n || g >= n) {       cout << min(b, g) + 1;     } else {       cout << b + g - n + 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k = 0;     string home;     cin >> n;     cin >> home;     for (int i = 0; i < n; i++) {       string now;       cin >> now;       now = now.substr(5, 3);       if (now == home) k++;     }     if (k == n - k)       cout <<  home ;     else       cout <<  contest ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   using min_heap = priority_queue<T, vector<T>, greater<T>>;   struct RangeIncrement {     vector<long long> tree, lazy;     RangeIncrement(int n) : tree(n << 2), lazy(n << 2) {}     void refresh(int i, int l, int r) {       if (lazy[i] != 0) {         tree[i] += lazy[i] * (r - l + 1);         if (l < r) {           int lc = i << 1, rc = (i << 1) + 1;           lazy[lc] += lazy[i];           lazy[rc] += lazy[i];         }         lazy[i] = 0;       }     }     void update(int i, int l, int r, int ul, int ur, long long x) {       refresh(i, l, r);       if (r < ul || l > ur) {         return;       } else if (ul <= l && r <= ur) {         lazy[i] += x;         refresh(i, l, r);       } else {         int m = l + r >> 1;         int lc = i << 1, rc = (i << 1) + 1;         update(lc, l, m, ul, ur, x);         update(rc, m + 1, r, ul, ur, x);         tree[i] = tree[lc] + tree[rc];       }     }     long long query(int i, int l, int r, int ql, int qr) {       refresh(i, l, r);       if (r < ql || l > qr) {         return 0;       } else if (ql <= l && r <= qr) {         return tree[i];       } else {         int m = l + r >> 1;         int lc = i << 1, rc = (i << 1) + 1;         return query(lc, l, m, ql, qr) + query(rc, m + 1, r, ql, qr);       }     }   };   template <class T>   struct DisjointRanges {     struct Range {       int l, r;       T x;       Range(int l, const pair<int, T>& p) : l(l), r(p.first), x(p.second) {}     };     map<int, pair<int, T>> s;     vector<Range> update(int l, int r, T x) {       vector<Range> bye;       auto last = s.upper_bound(r);       if (last != s.begin()) {         auto it = prev(last);         if (it->second.first > r) {           last = s.emplace_hint(last, r + 1, it->second);           it->second.first = r;         }       }       auto first = s.lower_bound(l);       if (first != s.begin()) {         auto it = prev(first);         if (it->second.first >= l) {           bye.emplace_back(l, it->second);           it->second.first = l - 1;         }       }       while (first != last) {         bye.emplace_back(first->first, first->second);         first = s.erase(first);       }       s.emplace_hint(last, l, make_pair(r, x));       return bye;     }   };   int main() {     int n, m;     scanf( %d %d , &n, &m);     RangeIncrement ri(n);     DisjointRanges<int> dr;     for (int i = 1; i <= n; i++) {       dr.update(i, i, i);     }     while (m--) {       int o, l, r, x;       scanf( %d %d %d , &o, &l, &r);       switch (o) {         case 1: {           scanf( %d , &x);           auto v = dr.update(l, r, x);           for (auto it : v) {             ri.update(1, 1, n, it.l, it.r, abs(x - it.x));           }           break;         }         case 2: {           printf( %lld n , ri.query(1, 1, n, l, r));           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int cnt[100100];   int R[100100];   int n;   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return res;   }   int main() {     memset(cnt, 0, sizeof(cnt));     scanf( %d , &n);     int maxA = 0;     for (int i = 1; i <= n; i++) {       int tmp;       scanf( %d , &tmp);       cnt[tmp]++;       maxA = max(maxA, tmp);     }     for (int i = maxA; i >= 1; i--) cnt[i] += cnt[i + 1];     long long ans = 0;     for (int i = 1; i <= maxA; i++) {       int tot = 0;       for (int j = 1; j * j <= i; j++) {         if (i % j == 0) {           R[tot++] = j;           if (j * j != i) {             R[tot++] = i / j;           }         }       }       sort(R, R + tot);       long long tmp =           (power(tot, cnt[R[tot - 1]]) -            power(tot - 1, cnt[R[tot - 1]]) % 1000000007 + 1000000007) %           1000000007;       for (int j = 0; j < tot - 1; j++)         tmp = (tmp * power(j + 1, cnt[R[j]] - cnt[R[j + 1]])) % 1000000007;       ans = (ans + tmp) % 1000000007;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500100;   const int maxp = 40;   int n, q;   double d[maxn][maxp];   int p[maxn];   void upd(int v, int k, double x) {     while (v && k < maxp) {       double a = d[v][k];       d[v][k] *= x;       x = (d[v][k] + 1) / (a + 1);       v = p[v];       k++;     }   }   int main() {     ios_base::sync_with_stdio(0);     for (int i = 0; i < maxn; i++)       for (int j = 0; j < maxp; j++) d[i][j] = 1;     cin >> q;     n = 1;     for (int i = 0; i < q; i++) {       int qtype, v;       cin >> qtype >> v;       if (qtype == 1) {         p[++n] = v;         upd(n, 0, 0);       } else {         double ans = 0;         for (int j = 1; j < maxp; j++) ans += (1 - d[v][j]);         cout << fixed << setprecision(10) << ans <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll INF = 1e14 + 7;   using vi = vector<int>;   using pii = pair<int, int>;   using pli = pair<ll, int>;   int ask(int i, int j) {     cout <<  ?   << i <<     << j << endl;     int ans;     cin >> ans;     return ans;   }   int main() {     int n;     cin >> n;     vi ans(n + 4), curr(n + 4);     curr[0] = ask(1, n);     curr[1] = ask(2, n);     ans[1] = curr[0] - curr[1];     for (int i = 2; i <= n - 1; i++) {       curr[i] = ask(i - 1, i);       ans[i] = curr[i] - ans[i - 1];     }     ans[n] = curr[0];     for (int i = 1; i < n; i++) {       ans[n] -= ans[i];     }     cout <<  ! ;     for (int i = 1; i <= n; i++) {       cout <<     << ans[i];     }     cout << endl;     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200005];   int b[200005];   bool f[200005];   int main() {     int q, n;     cin >> q;     while (q--) {       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];         b[i] = 1;         f[i] = 0;       }       for (int i = 1; i <= n; i++) {         int j = i;         if (f[i] == 1) continue;         f[i] = 1;         int ctr = 1;         while (a[j] != i) {           ctr++;           f[j] = 1;           j = a[j];         }         j = i;         while (a[j] != i) {           b[j] = ctr;           j = a[j];         }       }       for (int i = 1; i <= n; i++) cout << b[i] <<    ;       cout <<   n ;     }   }