malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int maxn = 222222;   int main(int argc, char const *argv[]) {     long long s, x;     cin >> s >> x;     if (s < x || (s - x) % 2) {       puts( 0 );     } else {       long long c = (s - x) / 2;       long long ans = 1;       for (int i = 0; i < 40; ++i) {         long long b1 = (x >> i) & 1;         long long b2 = (c >> i) & 1;         if (b1 && b2)           ans = 0;         else if (b1)           ans *= 2L;       }       if (c == 0) ans -= 2;       cout << (ans) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int n;   int oddb, evenb, oddr, evenr;   int main() {     cin >> n;     cin >> s;     int ans = 0;     for (int i = 0; i < n; i++) {       if (i % 2 == 0) {         if (s[i] ==  b )           evenb++;         else if (s[i] ==  r )           evenr++;       } else if (i % 2 == 1) {         if (s[i] ==  r )           oddr++;         else if (s[i] ==  b )           oddb++;       }     }     ans = min(max(oddr, evenb), max(oddb, evenr));     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int s[4];   int main() {     long long int x, y;     while (scanf( %I64d%I64d , &x, &y) == 2) {       s[0] = y;       s[1] = y;       s[2] = y;       sort(s, s + 3);       long long int cnt = 0;       while (1) {         if (s[0] == x && s[1] == x && s[2] == x) {           break;         }         if (s[1] + s[2] - 1 > x) {           s[0] = x;         } else {           s[0] = s[1] + s[2] - 1;         }         cnt++;         sort(s, s + 3);       }       printf( %I64d n , cnt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000100;   const int inf = 1000000007;   int dp[N][2], n, m[2], t, tot = 0, g[N][2], path[N], ans[N];   struct nd {     int d, id;   } a[N][2];   struct element {     int d, id[2];   } b[N];   struct point {     int x, y;   } po[N];   inline int read() {     int x = 0;     char ch = getchar();     while ((ch <  0 ) || (ch >  9 )) ch = getchar();     while ((ch >=  0 ) && (ch <=  9 )) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   void calc(int i, int j) {     if (dp[i - 1][j] == -1) {       g[i][j] = -1;       return;     }     if (!b[i].id[j])       g[i][j] = dp[i - 1][j] + b[i].d - b[i - 1].d;     else if (dp[i - 1][j] + b[i].d - b[i - 1].d <= t)       g[i][j] = -1;     else       g[i][j] = dp[i - 1][j] + b[i].d - b[i - 1].d - t;   }   void upd(int i, int j) {     dp[i][j] = g[i][j];     if (!b[i].id[j]) dp[i][j] = max(dp[i][j], min(g[i][j ^ 1], t));   }   int main() {     int i, j, k, nw, x, len[2], p[2], tmp, st;     scanf( %d%d%d%d , &n, &m[0], &m[1], &t);     if (m[0] + m[1] == 0) {       printf( Yes n0 n n0 n n );       return 0;     }     for (i = 0; i <= 1; i++) {       len[i] = 0;       for (j = 1; j <= m[i]; j++) {         x = read();         if (a[len[i]][i].d == x)           a[len[i]][i].id = 1;         else           a[++len[i]][i] = (nd){x, 1};         a[++len[i]][i] = (nd){x + 1, 0};       }       a[len[i] + 1][i] = (nd){inf, 0};     }     tot = 0;     memset(b, 0, sizeof(b));     for (p[0] = p[1] = 1; ((p[0] <= len[0]) || (p[1] <= len[1]));) {       if (a[p[0]][0].d <= a[p[1]][1].d)         nw = 0;       else         nw = 1;       if (b[tot].d != a[p[nw]][nw].d) b[++tot].d = a[p[nw]][nw].d;       b[tot].id[nw] = a[p[nw]][nw].id;       p[nw]++;     }     dp[0][0] = dp[0][1] = 0;     for (i = 1; i <= tot; i++) {       for (j = 0; j <= 1; j++) calc(i, j);       for (j = 0; j <= 1; j++) upd(i, j);     }     if ((dp[tot][0] == -1) && (dp[tot][1] == -1))       printf( No n );     else {       printf( Yes n );       if (g[tot][0] != -1)         path[tot] = 0;       else         path[tot] = 1;       for (i = tot - 1; i; i--)         if ((g[i][path[i + 1]] != -1) &&             (b[i + 1].d - b[i].d + g[i][path[i + 1]] -                  b[i + 1].id[path[i + 1]] * t ==              g[i + 1][path[i + 1]]))           path[i] = path[i + 1];         else           path[i] = path[i + 1] ^ 1;       ans[0] = 0;       for (i = 1; i <= tot; i++)         if (path[i - 1] ^ path[i]) ans[++ans[0]] = b[i - 1].d;       printf( %d n , ans[0]);       for (i = 1; i <= ans[0]; i++) printf( %d  , ans[i]);       printf(  n );       ans[0] = 0;       for (i = 1; i <= tot; i = j + 1) {         j = i;         while ((j <= tot) && (path[j + 1] == path[i])) j++;         tmp = 0;         for (k = i; k <= j; k++) tmp += b[k].id[path[i]];         st = b[i - 1].d + t - dp[i - 1][path[i]];         for (k = 1; k <= tmp; k++, st += t)           po[++ans[0]] = (point){st, path[i] + 1};       }       printf( %d n , ans[0]);       for (i = 1; i <= ans[0]; i++) printf( %d %d n , po[i].x, po[i].y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void FAST_IO() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   const int N = 3e5 + 5;   long long n, k, A, B;   long long a[N];   inline long long dfs(long long l, long long r) {     long long now = upper_bound(a, a + k, r) - lower_bound(a, a + k, l);     if (now == 0) return A;     if (l == r) return (now == 0 ? A : now * B);     long long mid = (l + r) >> 1;     long long sum = dfs(l, mid) + dfs(mid + 1, r);     sum = now * B * (r - l + 1) > sum ? sum : now * B * (r - l + 1);     return sum;   }   signed main() {     FAST_IO();     cin >> n >> k >> A >> B;     for (int i = 0; i < k; i++) {       cin >> a[i];     }     sort(a, a + k);     cout << dfs(1ll, 1ll << n) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long n, m;     cin >> n >> m;     vector<set<long long>> v((size_t)n);     auto add = [&](long long a, long long b) { v[a].insert((b - a + n) % n); };     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       a--, b--;       add(a, b);       add(b, a);     }     bool o = false;     for (long long j = 2, k = n; j <= k; j++) {       if (k % j == 0) {         bool g = true;         for (long long i = 0; i < n - n / j; i++) {           if (v[i] != v[i + n / j]) {             g = false;             break;           }         }         if (g) {           o = true;           break;         }       }       while (k % j == 0) {         k /= j;       }     }     cout << (o ?  Yes  :  No ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXSIZE = 10000020;   int bufpos;   char buf[MAXSIZE];   void init() {     buf[fread(buf, 1, MAXSIZE, stdin)] =   0 ;     bufpos = 0;   }   int readint() {     int val = 0;     for (; !isdigit(buf[bufpos]); bufpos++)       ;     for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + buf[bufpos] -  0 ;     return val;   }   char readchar() {     for (; isspace(buf[bufpos]); bufpos++)       ;     return buf[bufpos++];   }   int readstr(char* s) {     int cur = 0;     for (; isspace(buf[bufpos]); bufpos++)       ;     for (; !isspace(buf[bufpos]); bufpos++) s[cur++] = buf[bufpos];     s[cur] =   0 ;     return cur;   }   char s[5003], w[5003];   int main() {     init();     int n = readstr(s + 1);     bool flag = true;     for (int i = 1; i <= n; i++) {       if (n % 2 == 1 && i * 2 == n + 1) continue;       if (s[i] != s[1]) {         flag = false;         break;       }     }     if (flag) return puts( Impossible ), 0;     for (int i = 1; i < n; i++) {       int cur = 0;       for (int j = i + 1; j <= n; j++) w[++cur] = s[j];       for (int j = 1; j <= i; j++) w[++cur] = s[j];       if (!strcmp(s + 1, w + 1)) continue;       bool flag = true;       for (int j = 1; j <= n; j++)         if (w[j] != w[n - j + 1]) {           flag = false;           break;         }       if (flag) return puts( 1 ), 0;     }     puts( 2 );   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   std::vector<int> val(500005);   std::map<int, pair<int, int> > edges;   std::vector<pair<int, int> > query(500005);   int vis[500005];   int par[500005];   set<pair<int, int> > ss[500005];   int sz[500005];   std::vector<pair<int, int> > changes[500005];   int st[500005], en[500005];   int getpar(int x) {     if (par[x] == x)       return x;     else       return getpar(par[x]);   }   void merge(int n1, int n2, int idx) {     int p1 = getpar(n1);     int p2 = getpar(n2);     if (p1 == p2) return;     if (sz[p1] > sz[p2]) swap(p1, p2);     sz[p2] += sz[p1];     sz[p1] = 0;     for (auto i : ss[p1]) {       ss[p2].insert(i);     }     par[p1] = p2;     if (idx != -1) {       st[idx] = p1;       en[idx] = p2;       for (auto i : ss[p1]) {         changes[idx].push_back(i);       }     }     ss[p1].clear();   }   int getans(int node) {     int pp = getpar(node);     pair<int, int> zz = *(ss[pp].rbegin());     cout << zz.first <<   n ;     auto it = ss[pp].rbegin();     ss[pp].erase(zz);     val[zz.second] = 0;     ss[pp].insert({val[zz.second], zz.second});     return zz.first;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (int i = 1; i < n + 1; i++) {       cin >> val[i];       sz[i] = 1;       par[i] = i;       ss[par[i]].insert({val[i], i});     }     for (int i = 1; i < m + 1; i++) {       int x, y;       cin >> x >> y;       edges[i] = {x, y};     }     for (int i = 1; i < q + 1; i++) {       cin >> query[i].first >> query[i].second;       if (query[i].first == 2) {         vis[query[i].second] = 1;       }     }     for (int i = 1; i < m + 1; i++) {       if (!vis[i]) {         merge(edges[i].first, edges[i].second, -1);       }     }     for (int i = q; i >= 1; i--) {       if (query[i].first == 2) {         merge(edges[query[i].second].first, edges[query[i].second].second, i);       }     }     for (int i = 1; i < q + 1; i++) {       if (query[i].first == 1) {         getans(query[i].second);       } else {         int st1 = st[i];         int en1 = en[i];         ss[st1].clear();         for (auto j : changes[i]) {           ss[st1].insert({val[j.second], j.second});           ss[en1].erase({val[j.second], j.second});         }         par[st1] = st1;       }     }   }
#include <bits/stdc++.h>   const int bufSize = 1e6;   using namespace std;   inline char nc() {     return getchar();     static char buf[bufSize], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline void read(char* s) {     static char c;     for (; !isalpha(c); c = nc())       ;     for (; isalpha(c); c = nc()) *s++ = c;     *s =   0 ;   }   template <typename T>   inline T read(T& r) {     static char c;     static int flag;     flag = 1, r = 0;     for (c = nc(); !isdigit(c); c = nc())       if (c ==  - ) flag = -1;     for (; isdigit(c); c = nc()) r = r * 10 + c - 48;     return r *= flag;   }   const int maxn = 1e5 + 100;   const int maxm = 22;   int T, n;   char A[maxn], B[maxn];   int G[maxm][maxm];   int G2[maxm];   vector<int> s[maxm];   int fa[maxm];   int find(const int& x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   inline void merge(int x, int y) {     x = find(x), y = find(y);     if (x == y) return;     if (s[x].size() < s[y].size()) swap(x, y);     fa[y] = x;     for (vector<int>::iterator it = s[y].begin(); it != s[y].end(); ++it)       s[x].push_back(*it);     s[y].clear();   }   int f[1 << 21], num[1 << 21];   inline void init() {     for (int i = 1; i <= 20; ++i) fa[i] = i, s[i].clear(), s[i].push_back(i);     for (int i = 1; i <= 20; ++i)       for (int j = 1; j <= 20; ++j) G[i][j] = 0;   }   int main() {     for (int i = 0; i < (1 << 20); ++i)       for (int x = i; x; x >>= 1) num[i] += (x & 1);     read(T);     while (T--) {       read(n);       read(A + 1), read(B + 1);       init();       for (int i = 1; i <= n; ++i) {         if (A[i] == B[i]) continue;         G[A[i] -  a  + 1][B[i] -  a  + 1] = 1;         merge(A[i] -  a  + 1, B[i] -  a  + 1);       }       int ans = 0;       for (int i = 1; i <= 20; ++i) {         if (find(i) != i) continue;         for (unsigned int j = 0; j < s[i].size(); ++j) G2[j] = 0;         for (unsigned int j = 0; j < s[i].size(); ++j)           for (unsigned int k = 0; k < s[i].size(); ++k)             if (G[s[i][j]][s[i][k]]) G2[j] |= (1 << k);         int maxx = (1 << (int)s[i].size());         for (int status = 0; status < maxx; ++status) f[status] = 0;         f[0] = 1;         int res = 0;         for (int status = 0; status < maxx; ++status) {           if (!f[status]) continue;           res = max(res, num[status]);           for (unsigned int j = 0; j < s[i].size(); ++j)             if (!(status & (1 << j)) && !(G2[j] & status))               f[status | (1 << j)] = 1;         }         ans += 2 * s[i].size() - res - 1;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve(long long int test) {     long long int n;     cin >> n;     cout << n << endl;     for (long long int i = 1; i <= n; i++) cout << i <<    ;     cout << endl;   }   int main() {     long long int t = 1, test = 1;     cin >> t;     while (t--) {       solve(test++);     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 303303;   const int Max = 101101;   int n, S, L;   int a[Max];   int lg[Max];   struct sparse {     int g, h;   };   sparse s[22][Max];   void build_table() {     for (int i = 1; i <= n; i++) {       s[0][i].g = a[i];       s[0][i].h = a[i];     }     for (int i = 1; i <= lg[n]; i++) {       for (int j = 1; j <= n - (1 << i) + 1; j++) {         s[i][j] = s[i - 1][j];         int G = s[i - 1][j + (1 << (i - 1))].g;         int H = s[i - 1][j + (1 << (i - 1))].h;         if (G < s[i][j].g) s[i][j].g = G;         if (H > s[i][j].h) s[i][j].h = H;       }     }     return;   }   int get_table(int L, int R) {     int len = R - L + 1;     int G1 = s[lg[len]][L].g;     int H1 = s[lg[len]][L].h;     int G2 = s[lg[len]][R - (1 << lg[len]) + 1].g;     int H2 = s[lg[len]][R - (1 << lg[len]) + 1].h;     int G, H;     if (G1 <= G2)       G = G1;     else       G = G2;     if (H1 >= H2)       H = H1;     else       H = H2;     int result = H - G;     return result;   }   int tree[Max * 11];   int get(int v, int L, int R, int pos) {     if (L == R) return tree[v];     if (pos <= (L + R) / 2)       return get(2 * v + 1, L, (L + R) / 2, pos);     else       return get(2 * v + 2, (L + R) / 2 + 1, R, pos);   }   int get_min(int v, int L, int R, int l, int r) {     if (l > R || L > r) return INF;     if (l <= L && R <= r) return tree[v];     int M1 = get_min(2 * v + 1, L, (L + R) / 2, l, r);     int M2 = get_min(2 * v + 2, (L + R) / 2 + 1, R, l, r);     if (M1 <= M2)       return M1;     else       return M2;   }   void push(int v, int L, int R, int pos, int num) {     if (L == R) {       tree[v] = num;       return;     }     if (pos <= (L + R) / 2)       push(2 * v + 1, L, (L + R) / 2, pos, num);     else       push(2 * v + 2, (L + R) / 2 + 1, R, pos, num);     tree[v] = tree[2 * v + 1];     if (tree[2 * v + 2] < tree[v]) tree[v] = tree[2 * v + 2];     return;   }   int main() {     cin >> n >> S >> L;     for (int i = 1; i <= n; i++) cin >> a[i];     lg[1] = 0;     int t = 1;     for (int i = 2; i <= n; i++) {       lg[i] = lg[i - 1];       if (t * 2 == i) {         t *= 2;         lg[i]++;       }     }     build_table();     for (int i = 0; i < Max * 11; i++) tree[i] = INF;     for (int i = L; i <= n; i++) {       int raz = get_table(i - L + 1, i);       if (raz <= S) {         int LL = 1;         int RR = i - L + 1;         int start;         while (true) {           if (LL == RR) {             start = LL;             break;           }           int MM = (LL + RR) / 2;           int raz_new = get_table(MM, i);           if (raz_new <= S)             RR = MM;           else             LL = MM + 1;         }         if (start == 1)           push(0, 1, n, i, 1);         else {           int dp = get_min(0, 1, n, start - 1, i - L);           if (dp != INF) push(0, 1, n, i, dp + 1);         }       }     }     int ans = get(0, 1, n, n);     if (ans == INF)       cout <<  -1  << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long q1, q2;     cin >> q1 >> q2;     long long w1, w2;     cin >> w1 >> w2;     long long e1, e2;     cin >> e1 >> e2;     long long l1 = (q2 - w2) * (w1 - e1);     long long l2 = (q1 - w1) * (w2 - e2);     if (l2 > l1) return cout <<  LEFT , 0;     if (l1 > l2) return cout <<  RIGHT , 0;     cout <<  TOWARDS ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int inline read() {     int num = 0, neg = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (isdigit(c)) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num * neg;   }   const int maxn = 100010, mod = 1e9 + 7;   int n, m, ans = 2, f[maxn];   int main() {     n = read();     m = read();     if (n < m) swap(n, m);     f[1] = 4;     for (int i = 2; i <= m; i++) f[i] = (f[i - 1] + f[i - 2]) % mod;     for (int i = 1; i < m; i++) ans = (ans + f[i]) % mod;     f[1] = 2;     for (int i = 2; i <= n; i++) f[i] = (f[i - 1] + f[i - 2]) % mod;     for (int i = m + 1; i <= n; i++) ans = (ans + f[i - 1]) % mod;     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[500005], l = 1, r, b[500005];   queue<int> Q;   bool flag = false;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) a[i] = i & -i;     for (int i = 1; i <= n; ++i) b[i] = 1;     r = n;     while (m--) {       int opt, x, y;       scanf( %d , &opt);       if (opt == 1) {         scanf( %d , &x);         if (flag)           x = r - x + 1;         else           x += l;         if (r - x + 1 > x - l)           while (l < x) {             int tmp = 0;             for (int j = l; j; j -= j & -j) tmp += a[j];             for (int j = l - 1; j; j -= j & -j) tmp -= a[j];             for (int j = l; j <= n; j += j & -j) a[j] -= tmp;             b[x + x - l - 1] += b[l];             b[l] = 0;             for (int j = x + x - l - 1; j <= n; j += j & -j) a[j] += tmp;             l++;             flag = false;           }         else           while (r >= x) {             for (int i = x; i <= r; ++i) {               int tmp = 0;               for (int j = i; j; j -= j & -j) tmp += a[j];               for (int j = i - 1; j; j -= j & -j) tmp -= a[j];               for (int j = i; j <= n; j += j & -j) a[j] -= tmp;               b[i] = 0;               Q.push(tmp);             }             for (int i = x - 1; i >= x - (r - x + 1); --i) {               int tmp = Q.front();               Q.pop();               for (int j = i; j <= n; j += j & -j) a[j] += tmp;               b[i] += tmp;             }             r = x - 1;             flag = true;           }       }       if (opt == 2) {         scanf( %d%d , &x, &y);         int xx, yy;         if (flag) {           xx = r - y;           yy = r - x;           x = xx, y = yy;         } else           x = x + l - 1, y = y + l - 1;         int ans = 0;         for (int j = y; j; j -= j & -j) ans += a[j];         for (int j = x; j; j -= j & -j) ans -= a[j];         printf( %d n , ans);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int a[500010];   pair<int, int> b[500010];   int c[500010];   int T, n, tot;   int main(void) {     T = 1;     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) {         scanf( %d , &a[i]);         b[i] = {a[i], -i};       }       sort(b + 1, b + 1 + n);       for (int i = 1; i <= n; ++i) {         if (-b[i].second >= b[i].first) {           int x = -(b[i].second + b[i].first);           int pos = upper_bound(c + 1, c + 1 + tot, x) - c;           c[pos] = x;           tot = max(pos, tot);         }       }       printf( %d n , tot);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   template <typename T>   void chmin(T &x, const T &y) {     if (x > y) x = y;   }   template <typename T>   void chmax(T &x, const T &y) {     if (x < y) x = y;   }   template <typename T>   T gcd(T x, T y) {     return y ? gcd(y, x % y) : x;   }   template <class T>   inline bool read(T &ret) {     char c = getchar();     int sgn;     if (c == EOF) return 0;     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     sgn = (c ==  - ) ? -1 : 1;     ret = (c ==  - ) ? 0 : (c -  0 );     while (static_cast<void>(c = getchar()), c >=  0  && c <=  9 )       ret = ret * 10 + (c -  0 );     ret *= sgn;     return 1;   }   template <class T>   inline void write(T x) {     if (x > 9) out(x / 10);     putchar(x % 10 +  0 );   }   const int N = 1e5 + 5;   int x[4], y[4], an[N], n;   void doit(int j) {     int k = 0;     for (int i = 0; i < (int)(4); ++i) y[i] = x[i];     while (true) {       if (j == 4 || y[j] == 0) break;       an[k++] = j;       --y[j];       if (j > 0 && y[j - 1] > 0)         --j;       else         ++j;     }     if (k == n) {       cout <<  YES  << endl << an[0];       for (int i = 1; i < (int)(n); ++i) cout <<     << an[i];       cout << endl;       exit(0);     }   }   void solve(int times) {     for (int i = 0; i < (int)(4); ++i) cin >> x[i], n += x[i];     for (int j = 0; j < (int)(4); ++j) doit(j);     cout <<  NO  << endl;   }   void Init() {}   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int times = 1;     {       solve(times++);       Init();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n = 0;     cin >> n;     int a[n], res[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       res[i] = 0;     }     for (int i = 0; i < n - 1; i++) {       if (i) res[i] = res[i - 1];       while (a[i]) {         int t = 0;         for (t = 0; i + (1 << t) < n; t++)           ;         t--;         a[i]--;         a[i + (1 << t)]++;         res[i]++;       }     }     for (int i = 0; i < n - 1; i++) cout << res[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string str;     cin >> n >> str;     int p = 0;     if (n % 2 == 1) {       p = 3;       cout << str.substr(0, 3);       if (n != 3) cout <<  - ;     }     for (int i = p; i < str.length(); i += 2) {       cout << str.substr(i, 2);       if (i != str.length() - 2) cout <<  - ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3030;   struct dsu {     int par[MAXN];     void clear() {       for (int i = 0; i < MAXN; ++i) par[i] = i;     }     int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }     bool join(int u, int v) {       if ((u = find(u)) == (v = find(v))) return false;       par[v] = u;       return true;     }   } dsu;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i], a[i]--;     int m;     cin >> m;     vector<pair<int, int>> moves;     int step = 0;     while (true) {       dsu.clear();       int cst = 0;       for (int i = 0; i < n; ++i) cst += dsu.join(i, a[i]);       vector<int> b(n);       for (int i = 0; i < n; ++i) b[a[i]] = i;       if (cst < m) {         int u = 0;         int v = 1;         while (dsu.find(u) == dsu.find(v)) v++;         moves.emplace_back(u, v);         swap(a[u], a[v]);       } else if (cst > m) {         int u = 0;         while (a[u] == u) u++;         int v = u + 1;         while (dsu.find(v) != dsu.find(u)) v++;         moves.emplace_back(u, v);         swap(a[u], a[v]);       } else         break;     }     cout << moves.size() <<   n ;     for (auto &p : moves) cout << p.first + 1 <<     << p.second + 1 <<    ;     return 0;   }