malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 5e5 + 10;   vector<int> v[31];   long long par[31], X[31], Y[31], vis[31];   int xxx = 31;   void bfs() {     queue<tuple<int, int, int>> qu;     qu.push(make_tuple(1, 0, xxx));     vis[1] = 1;     X[1] = Y[1] = 1ll << xxx;     while (!qu.empty()) {       tuple<int, int, int> xx = qu.front();       qu.pop();       int s = get<0>(xx);       int dd = get<1>(xx);       int pp = get<2>(xx);       int dir = 1;       for (auto it : v[s]) {         if (vis[it]) continue;         vis[it] = 1;         if (dir == dd) dir++;         if (dir == 1) {           X[it] = X[s] + (1ll << (pp - 1));           Y[it] = Y[s];           qu.push(make_tuple(it, 2, pp - 1));           dir++;         } else if (dir == 2) {           X[it] = X[s] - (1ll << (pp - 1));           Y[it] = Y[s];           qu.push(make_tuple(it, 1, pp - 1));           dir++;         } else if (dir == 3) {           X[it] = X[s];           Y[it] = Y[s] - (1ll << (pp - 1));           qu.push(make_tuple(it, 4, pp - 1));           dir++;         } else {           X[it] = X[s];           Y[it] = Y[s] + (1ll << (pp - 1));           qu.push(make_tuple(it, 3, pp - 1));           dir++;         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int flag = 0;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);       if (v[a].size() > 4 || v[b].size() > 4) flag = 1;     }     if (flag)       puts( NO );     else {       bfs();       cout <<  YES n ;       for (int i = 1; i <= n; i++) cout << X[i] <<     << Y[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 233, mxzt = (1 << 20) + 23;   int f[21][mxzt], tmp[2][mxzt][20];   int stv[maxn];   int i, j, k, n, m;   char s[maxn];   int ra, fh;   char rx;   inline int read() {     rx = getchar(), ra = 0, fh = 1;     while (rx < 48) rx ==  -  && (fh = -1), rx = getchar();     while (rx > 47) ra = ra * 10 + rx - 48, rx = getchar();     return ra * fh;   }   inline int getnum1(int x) {     int n = 0;     while (x) n += x & 1, x >>= 1;     return n;   }   inline int min(int a, int b) { return a < b ? a : b; }   int main() {     n = read(), m = read();     int mx = 1 << n;     for (i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (j = 1; j <= m; j++) stv[j] = stv[j] << 1 | (s[j] - 48);     }     for (i = 1; i <= m; i++) f[0][stv[i]]++;     int zt, p, nf;     bool now = 1, pre = 0;     int *nt;     for (i = 1; i <= n; i++, swap(now, pre)) {       for (zt = 0; zt < mx; zt++) {         for (nf = p = 0, nt = tmp[now][zt]; p < n; p++, nt++)           nf += (*nt = f[i - 1][zt ^ (1 << p)] - tmp[pre][zt ^ (1 << p)][p]);         f[i][zt] = nf / i;       }     }     int ans = 1e9;     for (zt = 0; zt < mx; zt++) {       k = 0;       for (j = 0; j <= n && k < ans; j++) k += min(j, n - j) * f[j][zt];       if (j > n) ans = k;     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   int p;   struct seg {     std::vector<int64_t> cuts;     int64_t sum;     int64_t operator()(int64_t x) const {       return x + sum -              p * int64_t(std::upper_bound(begin(cuts), end(cuts), x) -                          begin(cuts));     }   };   seg operator*(seg const& a, seg const& b) {     for (unsigned i = 1; i < a.cuts.size(); ++i)       assert(a.cuts[i] - a.cuts[i - 1] >= p);     for (unsigned i = 1; i < b.cuts.size(); ++i)       assert(b.cuts[i] - b.cuts[i - 1] >= p);     seg out;     out.sum = a.sum + b.sum;     out.cuts.reserve(a.cuts.size() + b.cuts.size());     int64_t x = INT64_MIN / 2;     auto iter1 = begin(a.cuts);     auto iter2 = begin(b.cuts);     while (true) {       auto x1 = x + a.sum - p * int64_t(iter1 - begin(a.cuts));       auto x2 = x1 + b.sum - p * int64_t(iter2 - begin(b.cuts));       assert(iter1 == std::upper_bound(begin(a.cuts), end(a.cuts), x));       assert(a(x) == x1);       assert(iter2 == std::upper_bound(begin(b.cuts), end(b.cuts), x1));       assert(b(x1) == x2);       auto d1 = iter1 == end(a.cuts) ? INT64_MAX : *iter1 - x;       auto d2 = iter2 == end(b.cuts) ? INT64_MAX : *iter2 - x1;       assert(d1 > 0);       assert(d2 > 0);       if (d1 != INT64_MAX)         assert(iter1 != std::upper_bound(begin(a.cuts), end(a.cuts), x + d1));       if (d2 < d1) {         assert(iter1 == std::upper_bound(begin(a.cuts), end(a.cuts), x + d2));         assert(a(x + d2) == x1 + d2);         assert(iter2 != std::upper_bound(begin(b.cuts), end(b.cuts), x1 + d2));         x += d2;         out.cuts.push_back(x);         ++iter2;       } else if (d1 == INT64_MAX) {         break;       } else {         x += d1;         ++iter1;         auto new_x1 = x1 + d1 - p;         assert(a(x) == new_x1);         assert(std::upper_bound(begin(b.cuts), end(b.cuts), new_x1) <= iter2);         if (iter2 != begin(b.cuts) and iter2[-1] > new_x1) {           --iter2;           assert(std::upper_bound(begin(b.cuts), end(b.cuts), new_x1) == iter2);         } else {           out.cuts.push_back(x);         }       }     }     assert(out.cuts.size() == a.cuts.size() + b.cuts.size());     return out;   }   std::vector<seg> st;   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     int n, nquery;     std::cin >> n >> nquery >> p;     st.resize(n * 2);     for (int i = n; i < 2 * n; ++i) {       int ai;       std::cin >> ai;       st[i].cuts.push_back(p - ai);       st[i].sum = ai;     }     for (int i = n; --i;) st[i] = st[i << 1] * st[i << 1 | 1];     while (nquery--) {       int l, r;       std::cin >> l >> r;       --l;       l += n;       r += n;       int64_t out = 0;       std::vector<seg*> pendr;       while (l < r) {         if (l & 1) out = st[l++](out);         if (r & 1) pendr.push_back(&(st[--r]));         l >>= 1;         r >>= 1;       }       while (not pendr.empty()) {         out = (*pendr.back())(out);         pendr.pop_back();       }       std::cout << out <<   n ;     }   }
#include <bits/stdc++.h>   int main() {     char s[5200] = {0}, next[5200] = {0}, p[5200] = {0}, t[5200] = {0};     while (scanf( %s , s + 1) != EOF) {       s[0] =  a ;       double sum = 0;       int f = 0;       while (sscanf(s,  %*[^0-9]%[0-9.]%[^ 0] , p, next) > 0) {         double num1 = 0, num2 = 0;         int len = strlen(p), flag = 0;         if (len > 3 && p[len - 3] ==  . ) {           sscanf(p + len - 3,  %lf , &num1);           flag = f = 1;         }         if (flag == 1) len = len - 3;         for (int i = 0; i < len; i++) {           if (p[i] ==  . ) continue;           num2 = num2 * 10 + (p[i] -  0 );         }         sum += num1 + num2;         strcpy(s, next);         memset(next, 0, sizeof(next));       }       sprintf(t,  %.2f , sum);       int len = strlen(t), k = 0;       char ans[5200];       if (f == 0) len -= 3;       if (f == 1) {         ans[k++] = t[--len];         ans[k++] = t[--len];         ans[k++] = t[--len];         if (ans[0] ==  0  && ans[1] ==  0 ) k = 0;       }       for (int i = len - 1, counts = 1; i >= 0; i--, counts++) {         if (counts % 3 == 1 && counts != 1) ans[k++] =  . ;         ans[k++] = t[i];       }       for (int i = k - 1; i >= 0; i--) printf( %c , ans[i]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, num[100100];   inline int as(int u) {     int a, b;     if (num[u]) return num[u];     printf( ? %d n , u);     fflush(stdout);     scanf( %d , &a);     return num[u] = a;   }   inline void pd(int u) {     if (as(u) == as(u + m)) {       printf( ! %d n , u);       exit(0);     }   }   int main() {     int i, j, l, r, mid, p, q;     cin >> n;     m = n / 2;     if (m % 2) {       puts( ! -1 );       return 0;     }     as(1), as(m + 1), pd(1);     l = 2, r = m;     for (; l <= r;) {       mid = ((l + r) >> 1);       p = as(mid), q = as(mid + m);       pd(mid);       if ((p > q) ^ (num[1] > num[m + 1]))         r = mid - 1;       else         l = mid + 1;     }   }
#include <bits/stdc++.h>   long num[1000000];   int main() {     long long ans;     long i, j, k, n;     long long max1, max2;     scanf( %ld , &n);     ans = 0;     for (i = 1; i <= n; i++) {       scanf( %ld , &num[i]);       ans += num[i];     }     max1 = 0;     max2 = 0;     for (i = 1; i <= n; i++) {       scanf( %ld , &num[i]);       if (num[i] > max1) {         max2 = max1;         max1 = num[i];       } else {         if (num[i] > max2) {           max2 = num[i];         }       }     }     if (max1 + max2 < ans) {       printf( NO n );     } else {       printf( YES n );     }     return 0;   }
#include <bits/stdc++.h>   long long n, m, Now, Ans, i;   long long sumi(long long a, long long b);   int main() {     scanf( %I64d %I64d , &n, &m);     Now = sumi(2, m);     if (Now == 0)       Now = 1000000009 - 1;     else       Now--;     Ans = 1;     for (i = 1; i <= n; i++) {       Ans *= Now;       Ans %= 1000000009;       if (Now == 0)         Now = 1000000009 - 1;       else         Now--;     }     printf( %I64d n , Ans);     return 0;   }   long long sumi(long long a, long long b) {     long long ret = 1, i, c = a;     for (i = 1; i <= b; i += i) {       if ((b & i) > 0) {         ret *= c;         ret %= 1000000009;       }       c *= c;       c %= 1000000009;     }     return ret;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m, val, i, j = 0, sum = 0, k = 0;     vector<long> toys;     vector<long> selected;     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> val;       toys.push_back(val);     }     sort(toys.begin(), toys.end());     for (i = 0; i < 1000000000; i++) {       if (j < (long)toys.size()) {         if (toys[j] == (i + 1)) {           j++;         } else {           if (sum + i + 1 <= m) {             selected.push_back(i + 1);             sum += i + 1;             k++;           } else {             break;           }         }       } else if (sum + i + 1 <= m) {         selected.push_back(i + 1);         sum += i + 1;         k++;       } else {         break;       }     }     cout << k << endl;     for (auto t : selected) {       cout << t <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   const long long inf = 0x3f3f3f3f3f3f3f3f;   int n, m, q, u[N], v[N], w[N];   long long d[2][N];   bool vis[N];   vector<pair<long long, int> > g[N];   pair<long long, int> pre[N];   void dij(int s, long long d[]) {     for (int i = (1); i < (n + 1); i++) d[i] = inf, vis[i] = 0;     d[s] = 0;     priority_queue<pair<long long, int> > q;     q.push(pair<long long, int>(0, s));     while (!q.empty()) {       int u = q.top().second;       q.pop();       if (vis[u]) continue;       vis[u] = 1;       for (auto it : g[u]) {         if (d[u] + w[it.second] < d[it.first]) {           d[it.first] = d[u] + w[it.second];           pre[it.first] = pair<long long, int>(u, it.second);           q.push(pair<long long, int>(-d[it.first], it.first));         }       }     }   }   int k[N], e[N];   bool used[N], in[N];   vector<long long> ad[N], del[N];   long long mn[N];   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = (1); i < (m + 1); i++) {       scanf( %d%d%d , &u[i], &v[i], &w[i]);       g[u[i]].push_back(pair<long long, int>(v[i], i));       g[v[i]].push_back(pair<long long, int>(u[i], i));     }     dij(n, d[1]);     dij(1, d[0]);     vector<int> vec;     for (int i = (2); i < (n + 1); i++) used[pre[i].second] = 1;     pre[1] = pair<long long, int>(0, 0);     for (int i = n; i >= 1; i = pre[i].first)       in[pre[i].second] = 1, vec.push_back(i);     int cnt = 0;     reverse(vec.begin(), vec.end());     for (auto v : vec) k[v] = ++cnt;     for (int i = (1); i < (n + 1); i++) {       if (d[0][i] == inf) continue;       if (!k[i]) {         int u = i;         for (; !k[u]; u = pre[u].first)           ;         for (int v = i; !k[v]; v = pre[v].first) k[v] = k[u];       }     }     for (int i = (1); i < (m + 1); i++) {       if (used[i]) continue;       int l = k[u[i]], r = k[v[i]];       if (l == r) continue;       if (l > r) swap(u[i], v[i]), swap(l, r);       ad[l].push_back(d[0][u[i]] + w[i] + d[1][v[i]]);       del[r].push_back(d[0][u[i]] + w[i] + d[1][v[i]]);     }     multiset<long long> S;     S.insert(inf);     for (int i = (1); i < (cnt); i++) {       for (auto v : del[i]) S.erase(S.find(v));       for (auto v : ad[i]) S.insert(v);       mn[i] = *(S.begin());     }     int x, y;     while (q--) {       scanf( %d%d , &x, &y);       long long ans = min(d[0][u[x]] + d[1][v[x]], d[0][v[x]] + d[1][u[x]]) + y;       if (!in[x]) {         ans = min(ans, d[0][n]);       } else {         ans = min(ans, mn[min(k[u[x]], k[v[x]])]);       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> graph[200002];   int visited[200002], sub[200002];   int subsize(int root) {     visited[root] = 1;     for (int child : graph[root]) {       if (!visited[child]) sub[root] += subsize(child);     }     return sub[root];   }   void destroy(int root, int par) {     for (int child : graph[root]) {       if (child != par && (sub[child] % 2 == 0)) destroy(child, root);     }     printf( %d n , root);     for (int child : graph[root]) {       if (child != par && (sub[child] & 1)) destroy(child, root);     }   }   int main() {     for (int i = 0; i < 200002; i++) sub[i] = 1;     int n, x;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (x) {         graph[x].push_back(i);         graph[i].push_back(x);       }     }     if (n % 2 == 0)       printf( NO );     else {       subsize(1);       printf( YES n );       destroy(1, 0);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, crush[100005], ans = -1;   bool exi[100005];   long long ms(int o, int x, int p) {     if (p > 2 * n) return -1;     if (crush[x] == x) return p ? -1 : 0;     if ((x == o) && p) return 0;     int t = ms(o, crush[x], p + 1);     return (t < 0 ? t : t + 1);   }   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &crush[i]);       exi[crush[i]] = 1;     }     for (int i = 1; i <= n; i++) {       if (!exi[i]) {         ans = -1;         break;       }       long long tmp = ms(i, i, 0);       if (tmp <= 0) tmp = 1;       tmp /= (2 - (tmp & 1));       ans = ans < 0 ? tmp : lcm(ans, tmp);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Array[100005], Left[100005];   int Right[100005];   int main() {     int N, i;     scanf( %d , &N);     for (i = 1; i <= N; ++i) {       scanf( %d , Array + i);       Left[i] = min(Left[i - 1] + 1, Array[i]);     }     for (i = N; i >= 1; --i) Right[i] = min(Right[i + 1] + 1, Array[i]);     int Ans = 0;     for (i = 1; i <= N; ++i) Ans = max(Ans, min(Left[i], Right[i]));     printf( %d n , Ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t;   int dp[21][5][11][11][2];   int solve(int pos, int h, int mn, int mx, bool w) {     if (mn > t - 1 || mx > t) return 0;     if (pos == n) return mx == t && mn == t - 1;     int &ref = dp[pos][h][mn][mx][w];     if (ref != -1) return ref;     ref = 0;     for (int i = 1; i < 5; ++i) {       if (i == h) continue;       bool wp = i > h;       if (!pos)         ref += solve(pos + 1, i, mn, mx, w);       else if (pos == 1)         ref += solve(pos + 1, i, mn, mx, wp);       else         ref += solve(pos + 1, i, mn + (!w & wp), mx + (w & !wp), wp);     }     return ref;   }   int main() {     scanf( %d %d , &n, &t);     memset(dp, -1, sizeof(dp));     int sol = solve(0, 0, 0, 0, 0);     printf( %d n , sol);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using uint = unsigned;   using ll = long long;   using ull = unsigned long long;   using vi = vector<int>;   using vvi = vector<vi>;   using vl = vector<ll>;   using vvl = vector<vl>;   using vd = vector<double>;   using vvd = vector<vd>;   using vs = vector<string>;   template <typename T1, typename T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename Tuple>   void print_tuple(ostream&, const Tuple&) {}   template <typename Car, typename... Cdr, typename Tuple>   void print_tuple(ostream& os, const Tuple& t) {     print_tuple<Cdr...>(os, t);     os << (sizeof...(Cdr) ?  ,  :   ) << get<sizeof...(Cdr)>(t);   }   template <typename... Args>   ostream& operator<<(ostream& os, const tuple<Args...>& t) {     print_tuple<Args...>(os <<  ( , t);     return os <<  ) ;   }   template <typename Ch, typename Tr, typename C>   basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, const C& c) {     os <<  [ ;     for (auto i = begin(c); i != end(c); ++i)       os << (i == begin(c) ?    :    ) << *i;     return os <<  ] ;   }   constexpr int INF = 1e9;   constexpr int MOD = 1e9 + 7;   constexpr double EPS = 1e-9;   int main() {     for (int n; cin >> n && n;) {       vi a(n);       for (int i = int(0); i < int(n); i++) cin >> a[i];       ll mx = *max_element(begin(a), end(a)),          sum = accumulate(begin(a), end(a), 0ll);       cout << max<ll>(2 * mx - sum, 0) + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   namespace IO {   char buf[1 << 22], *p1 = buf, *p2 = buf;   template <typename T>   inline void read(T &x) {     x = 0;     register char ch =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     while (!(ch >= 48 && ch <= 57))       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     while ((ch >= 48 && ch <= 57)) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   }  // namespace IO   using namespace IO;   const int N = 1e5 + 10, inf = 0x3f3f3f3f;   struct ALTXDY {     int tp, t, x, y, id;     bool operator<(ALTXDY const &a) const {       return x == a.x ? tp < a.tp : x < a.x;     }   };   ALTXDY q[N << 1];   int n, m, tot, bus[N], ans[N], c[N << 1], dat[N << 2], ls[N << 2], rs[N << 2];   void update(int &i, int l, int r, int x, int k) {     if (!i) i = ++tot;     if (bus[dat[i]] < bus[k]) dat[i] = k;     if (l == r) return;     int mid = (l + r) >> 1;     if (x <= mid)       update(ls[i], l, mid, x, k);     else       update(rs[i], mid + 1, r, x, k);   }   int query(int i, int l, int r, int x, int y, int val) {     if (l == r) return dat[i];     int mid = (l + r) >> 1, t = -1;     if (x <= mid && ls[i] && bus[dat[ls[i]]] >= val)       t = query(ls[i], l, mid, x, y, val);     if (t == -1 && y >= mid + 1 && rs[i] && bus[dat[rs[i]]] >= val)       t = query(rs[i], mid + 1, r, x, y, val);     return t;   }   int main() {     read(n, m);     for (int i = 1; i <= n; i++) {       int s, f, t;       read(s, f, t);       q[i] = (ALTXDY){0, t, s, f, i};       c[i] = t;       bus[i] = f;     }     for (int i = 1; i <= m; i++) {       int b, l, r;       read(l, r, b);       q[i + n] = (ALTXDY){1, b, l, r, i};       c[i + n] = b;     }     sort(c + 1, c + 1 + n + m);     register int k = unique(c + 1, c + 1 + n + m) - c - 1;     for (int i = 1; i <= n + m; i++)       q[i].t = lower_bound(c + 1, c + 1 + k, q[i].t) - c;     sort(q + 1, q + 1 + n + m);     register int rt = 0;     for (int i = 1; i <= n + m; i++)       if (q[i].tp == 0)         update(rt, 1, k, q[i].t, q[i].id);       else         ans[q[i].id] = query(rt, 1, k, q[i].t, k, q[i].y);     for (int i = 1; i <= m; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ini_pos;   vector<int> v[2020];   int a[2020], MAX;   map<int, int> mp;   int dist(int a, int b) {     if (a < b) swap(a, b);     return min(a - b, n - a + b);   }   void input() {     scanf( %d %d , &n, &ini_pos);     for (int i = 1; i <= n; i++) scanf( %d , a + i), mp[a[i]] = 0;     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {       mp[it->first] = ++MAX;     }     for (int i = 1; i <= n; i++) a[i] = mp[a[i]], v[a[i]].push_back(i);   }   int f[2020], en[2020];   int same[2020], Same[2020], nxt[2020];   void prepare() {     v[0].push_back(ini_pos);     for (int m = MAX; m >= 0; m--) {       if (m < MAX) {         for (int i, j = 0; j < v[m].size(); j++) {           i = v[m][j];           int t = m ? i : 0;           en[t] = -1;           for (int ii, jj = 0; jj < v[m + 1].size(); jj++) {             ii = v[m + 1][jj];             int d = dist(i, ii);             if (en[t] == -1 || en[t] > d + f[ii]) {               nxt[t] = ii;               en[t] = d + f[ii];             }           }         }       }       if (!m) break;       int s = v[m].size();       for (int ii, i, j = 0; j < s; j++) {         i = v[m][j];         ii = v[m][(j + 1) % s];         same[i] = +1;         Same[i] = ii;         f[i] = en[ii] + (n - (ii >= i ? ii - i : ii - i + n));         if (ii == i) {           f[i] = en[ii];           continue;         }         ii = v[m][(j - 1 + s) % s];         int ff = en[ii] + (n - (i >= ii ? i - ii : i - ii + n));         if (f[i] > ff) f[i] = ff, same[i] = -1, Same[i] = ii;       }     }   }   void move(int a, int b) {     int d = dist(a, b);     if (d == b - a || d == b + n - a)       printf( %+d n , d);     else       printf( %+d n , -d);   }   void a_a(int s, int cur, int type) {     if (type == -1) reverse(v[s].begin(), v[s].end());     for (int I = -1, i = 0; i < v[s].size(); i = (i + 1) % (int(v[s].size()))) {       int t = v[s][i];       if (I == -1) {         if (t == cur) I = i;         continue;       }       if (I == i) return;       move(cur, t);       cur = t;     }   }   void solve() {     int cur = ini_pos;     printf( %d n , en[0]);     for (int s = 0; s < MAX;) {       int t = nxt[s ? cur : 0];       move(cur, t);       cur = t;       ++s;       a_a(s, cur, -same[cur]);       cur = Same[cur];     }   }   int main() {     input();     prepare();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[201000];   long long vis[201000];   int main() {     int t;     cin >> t;     while (t--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), vis[i] = 0;       int m;       scanf( %d , &m);       for (int i = 1; i <= m; i++) {         long long x, y;         scanf( %lld%lld , &x, &y);         vis[y] = max(vis[y], x);       }       for (int i = n - 1; i >= 1; i--) {         if (vis[i] < vis[i + 1]) vis[i] = vis[i + 1];       }       long long ans = 1;       long long num = 0, co = 0;       int vis1 = 0;       for (int i = 1; i <= n; i++) {         num++;         if (vis[num] >= max(co, a[i])) {           co = max(co, a[i]);         } else {           ans++;           num--;           if (vis[1] < a[i]) vis1 = 1;           num = 1, co = a[i];         }       }       if (vis1)         printf( -1 n );       else         printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int k;     cin >> k;     if (k == 0) return cout <<  + n , 0;     vector<string> ats = { ++ ,  +* };     while (ats.size() < (1 << k)) {       auto cp = ats;       for (auto& s : cp)         for (auto& ch : s) ch = (ch ==  +  ?  *  :  + );       for (int i = 0; i < cp.size(); i++) {         ats.push_back(ats[i] + cp[i]);         ats[i] += ats[i];       }     }     for (auto& s : ats) cout << s <<   n ;   }