malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   vector<int> g[300005];   bool vis[300005];   int child[300005];   int mostchild[300005], par[300005];   int dfs(int u) {     vis[u] = true;     child[u]++;     for (int i = 0; i < g[u].size(); i++) {       if (!vis[g[u][i]]) {         vis[g[u][i]] = true;         int x = dfs(g[u][i]);         child[u] += x;         if (child[mostchild[u]] < x) mostchild[u] = g[u][i];       }     }     return child[u];   }   int res[300005];   void traverse(int u) {     if (u == 0) return;     vis[u] = true;     if (child[u] == 1) {       res[u] = u;       return;     }     traverse(mostchild[u]);     if (2 * child[mostchild[u]] > child[u]) {       int m = res[mostchild[u]];       while (2 * (child[u] - child[m]) > child[u]) m = par[m];       res[u] = m;     } else       res[u] = u;   }   int main() {     int n, q;     cin >> n >> q;     par[1] = 1;     for (int i = 2; i < n + 1; i++) {       scanf( %d , &par[i]);       g[par[i]].push_back(i);     }     memset(vis, false, sizeof(vis));     memset(mostchild, 0, sizeof(mostchild));     child[0] = 0;     dfs(1);     memset(vis, false, sizeof(vis));     for (int i = 1; i < n + 1; i++) {       if (!vis[i]) traverse(i);     }     for (int i = 0; i < q; i++) {       int a;       scanf( %d , &a);       printf( %d n , res[a]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   int x, n, m;   int main() {     cin >> t;     while (t--) {       cin >> x >> n >> m;       while (x > 20 && n) {         x = x / 2 + 10;         n--;       }       while (m) x -= 10, m--;       if (x > 0)         printf( NO n );       else         printf( YES n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, s;     cin >> a >> s;     sort(s.begin(), s.end());     int ind = s.length() - 1, n = a.length();     for (int i = 0; i < n; i++) {       if (ind >= 0 && s[ind] > a[i]) {         a[i] = s[ind];         ind--;       }     }     cout << a;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using vi = vector<int>;   using vl = vector<ll>;   using pii = pair<int, int>;   using vpii = vector<pair<int, int>>;   template <typename T>   using pque = priority_queue<T, vector<T>, greater<T>>;   constexpr int N = 212345, M = 16;   class Node {    public:     int a = 0;     Node *c[2] = {NULL, NULL};     Node *next(int a) {       if (c[a] == NULL) c[a] = new Node();       return c[a];     }   } *head = new Node();   vpii g[N];   vi v[M][M];   int p[N] = {};   template <class T>   void dfs(int a, int b, T func) {     if (a > b) {       func();       return;     };     for (int i = (0); i < ((a)); i++) {       for (int j : v[a][i]) p[j]++;       dfs(a + 1, b, func);       for (int j : v[a][i]) p[j]--;     }   }   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = (0); i < ((m)); i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       g[a].emplace_back(c, b);     }     for (int i = (1); i < (n + 1); i++) {       sort((g[i]).begin(), (g[i]).end());       for (int j = (0); j < (((int)g[i].size())); j++) {         v[g[i].size()][j].emplace_back(g[i][j].second);       }     }     for (int i = (1); i < (k); i++)       for (int j = (0); j < ((i)); j++) {         ;         for (int h : v[i][j])           ;         ;       }     dfs(1, min(6, k), [&]() {       for (int i = (1); i < (n + 1); i++)         ;       ;       Node *node = head;       for (int i = (1); i < (n + 1); i++) {         if (p[i] >= 2) return;         node = node->next(p[i]);       }       node->a++;     });     ;     int ans = 0;     dfs(min(7, k), k <= 6 ? 0 : k, [&]() {       Node *node = head;       for (int i = (1); i < (n + 1); i++) {         if (p[i] >= 2) return;         node = node->next(1 - p[i]);       }       ans += node->a;       ;     });     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int arr[200005] = {0};     long long int ans[200005] = {0};     int x, y, n, k, q;     cin >> n >> k >> q;     while (n--) {       cin >> x >> y;       arr[x]++;       arr[y + 1]--;     }     for (int i = 1; i <= 200000; i++) {       arr[i] += arr[i - 1];     }     for (int i = 1; i <= 200000; i++) {       if (arr[i] >= k)         ans[i] = ans[i - 1] + 1;       else         ans[i] = ans[i - 1];     }     while (q--) {       cin >> x >> y;       cout << ans[y] - ans[x - 1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:20000007 )   #pragma GCC optimize( unroll-loops )   const int N = (int)1e6 + 100;   const int maxn = (int)1e3 + 100;   const int base = (int)1e9;   const int mod = (int)1e9 + 7;   const int inf = INT_MAX;   const long long ll_inf = LLONG_MAX;   const long double pi = acos((long double)-1.0);   const long double eps = 1e-8;   void yes() { exit(!(printf( YES n ))); }   void no() { exit(!(printf( NO n ))); }   void solve() {     string s;     cin >> s;     int n = s.size();     if (n < 4) no();     set<char> S;     vector<int> Cnt(26);     for (char c : s) Cnt[c -  a ]++, S.insert(c);     int L = S.size();     if (L > 4) no();     if (3 <= L && L <= 4) yes();     if (L == 1) no();     if (L == 2) {       if (!any_of(Cnt.begin(), Cnt.end(),                   [&](int Count) -> bool { return Count >= 2; }))         no();       vector<int> others;       for (int i = 0; i < 26; ++i)         if (Cnt[i] >= 2) others.push_back(i);       if (others.size() >= 2)         yes();       else         no();     }     no();   }   int main() {     int T = 1;     for (; T; --T) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cout << x; }   void __print(char x) { cout <<      << x <<     ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cout <<  { ;     __print(x.first);     cout <<  , ;     __print(x.second);     cout <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cout <<  { ;     for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);     cout <<  } ;   }   void _print() { cout <<   n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   const int mod = 1e9 + 7, mxn = 1e5 + 1;   int solve() {     int n, m, k;     cin >> n >> m >> k;     vector<long long> v(n + 1);     for (long long i = (1); i < (n + 1); ++i) cin >> v[i];     vector<long long> pref(n + 1, 0);     pref[0] = 0;     for (long long i = (1); i < (n + 1); ++i) pref[i] = pref[i - 1] + v[i];     long long dp[n + 1][k + 1];     memset(dp, 0ll, sizeof(dp));     for (long long i = (1); i < (n + 1); ++i) {       for (long long j = (1); j < (k + 1); ++j) {         if (i - m >= 0)           dp[i][j] = max(dp[i - 1][j], dp[i - m][j - 1] + pref[i] - pref[i - m]);         else           dp[i][j] = dp[i - 1][j];       }     }     cout << dp[n][k] <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   constexpr int maxn = 1e5 + 10;   vector<int> topo;   vector<vector<pii>> pilha;   int ans[maxn];   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     for (auto& it : a) scanf( %d , &it);     for (int i = 0; i < n; i++) {       auto it = lower_bound((topo).begin(), (topo).end(), a[i]);       if (it == topo.end())         topo.push_back(a[i]), pilha.push_back({{a[i], i}});       else {         int pos = (int)(it - topo.begin());         topo[pos] = a[i];         pilha[pos].push_back({a[i], i});       }     }     vector<pii> valid = pilha.back();     if ((int)((valid).size()) > 1)       for (auto it : valid) ans[it.second] = 2;     else       ans[valid[0].second] = 3;     for (int i = (int)((pilha).size()) - 2; i >= 0; i--) {       assert((int)((valid).size()));       sort((valid).begin(), (valid).end());       vector<int> suf((int)((valid).size())), comp((int)((valid).size()));       suf.back() = valid.back().second;       for (int pos = (int)((valid).size()) - 2; pos >= 0; pos--)         suf[pos] = max(suf[pos + 1], valid[pos].second);       for (int j = 0; j < (int)((valid).size()); j++) comp[j] = valid[j].first;       valid.clear();       for (int j = 0; j < (int)((pilha[i]).size()); j++) {         auto it = upper_bound((comp).begin(), (comp).end(), pilha[i][j].first);         if (it == comp.end())           ans[pilha[i][j].second] = 1;         else {           int pos = (int)(it - comp.begin());           if (suf[pos] < pilha[i][j].second)             ans[pilha[i][j].second] = 1;           else             valid.push_back(pilha[i][j]);         }       }       if ((int)((valid).size()) > 1)         for (auto it : valid) ans[it.second] = 2;       else         ans[valid[0].second] = 3;     }     for (int i = 0; i < n; i++) printf( %d , ans[i]);     printf(  n );   }
#include<bits/stdc++.h>   using namespace std;      void solve(){    int n;    cin >> n;    int a[n];    for(int i=0;i<n;i++){     cin >> a[i];    }        vector<int> ans;    ans.push_back(0);        int current = a[0];    for(int i=1;i<n;i++){     int cans = (current|a[i])^a[i];     ans.push_back(cans);     current = current|a[i];    }        for(int i=0;i<n;i++){     cout << ans[i] <<    ;    }        cout << endl;   }      int main(){    int t=1;    cin >> t;    while(t--){     solve();    }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int len = s.length();     for (int i = 0; i < len;) {       if (s[i] !=  1 ) {         cout <<  NO  << endl;         return 0;       }       if (i + 3 <= len) {         if (s[i + 1] ==  4  and s[i + 2] ==  4 ) {           i += 3;         } else if (s[i + 1] ==  4 ) {           i += 2;         } else           ++i;       } else if (i + 2 <= len) {         if (s[i + 1] ==  4 ) {           i += 2;         } else           ++i;       } else         ++i;     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int res = 0, c;     while (c = getchar(), c <  0  || c >  9 )       ;     do {       res = (res << 3) + (res << 1) + (c ^ 48);     } while (c = getchar(), c >=  0  && c <=  9 );     return res;   }   const int inf = 0x3f3f3f3f;   const int maxn = 100010;   const int maxd = 8000010;   int T[maxd], s[maxn], lson[maxd], rson[maxd], val[maxd], tot;   int l[maxn], r[maxn], d[maxn];   vector<int> edge[maxn], lay[maxn];   int N, R, last, dep, dfn;   void dfs(int x, int dep) {     l[x] = ++dfn;     d[x] = dep;     ::dep = max(dep, ::dep);     lay[dep].push_back(x);     for (auto i : edge[x])       if (!l[i]) {         dfs(i, dep + 1);       }     r[x] = dfn;   }   void update(int to, int L, int R, int& rt) {     if (L == R) {       val[rt = ++tot] = s[to];       return;     }     int mid = L + R >> 1;     lson[++tot] = lson[rt];     rson[tot] = rson[rt];     rt = tot;     if (l[to] <= mid)       update(to, L, mid, lson[rt]);     else       update(to, mid + 1, R, rson[rt]);     val[rt] = min(val[lson[rt]], val[rson[rt]]);   }   int query(int l, int r, int L, int R, int rt) {     if (L >= l && R <= r) {       return val[rt];     }     int mid = L + R >> 1, res = inf;     if (mid >= l) res = query(l, r, L, mid, lson[rt]);     if (mid < r) res = min(res, query(l, r, mid + 1, R, rson[rt]));     return res;   }   int main() {     N = read(), R = read();     for (int i = 1; i <= N; i++) s[i] = read();     for (int i = 1; i < N; i++) {       int x = read(), y = read();       edge[x].push_back(y);       edge[y].push_back(x);     }     dfs(R, 1);     T[0] = lson[0] = rson[0] = 0;     val[0] = inf;     for (int d = 1; d <= dep; d++) {       T[d] = ++tot;       lson[tot] = lson[T[d - 1]];       rson[tot] = rson[T[d - 1]];       for (auto i : lay[d]) update(i, 1, N, T[d]);     }     int Q = read();     while (Q--) {       int X = (last + read()) % N + 1, K = (read() + last) % N;       printf( %d n , last = query(l[X], r[X], 1, N, T[min(dep, d[X] + K)]));     }   }
#include <bits/stdc++.h>   int main(void) {     int n;     std::cin >> n;     int arr[2 * n];     for (int i = 0; i < 2 * n; i++) std::cin >> arr[i];     int swc = 0;     for (int i = 0; i < 2 * n; i += 2) {       int pos = -1;       for (int j = i + 1; j < 2 * n; j++) {         if (arr[j] == arr[i]) {           pos = j;           break;         }       }       for (int j = pos; j > i + 1; j--) {         swc++;         std::swap(arr[j], arr[j - 1]);       }     }     std::cout << swc <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   const long long inf = 1e18;   int a[maxn];   vector<int> g[maxn];   bool c[maxn], ok[maxn];   int dpdown[maxn], dpup[maxn];   int salem[maxn];   int mxdown[maxn], mxup[maxn];   int cnt[maxn];   int sum[maxn];   int n;   int dip[maxn];   void dfsdown(int v, int p) {     ok[v] = c[v];     cnt[v] = 1;     sum[v] = c[v];     for (auto u : g[v])       if (u != p) dfsdown(u, v), cnt[v] += cnt[u], sum[v] += sum[u];     if (!c[v]) return;     for (auto u : g[v])       if (u != p)         if (ok[u])           salem[v] += cnt[u];         else {           ok[v] = 0;           mxdown[v] = max(mxdown[v], dpdown[u]);         }     dpdown[v] = mxdown[v] + salem[v] + 1;   }   void dfsup(int v, int p) {     int _mx = -1;     for (auto u : g[v])       if (u != p && c[u] && c[v])         mxup[u] = max(mxup[u], _mx), _mx = max(_mx, (1 - ok[u]) * dpdown[u]);     reverse(g[v].begin(), g[v].end());     _mx = -1;     for (auto u : g[v])       if (u != p && c[u] && c[v])         mxup[u] = max(mxup[u], _mx), _mx = max(_mx, (1 - ok[u]) * dpdown[u]);     for (auto u : g[v])       if (u != p)         if (c[u])           if (c[v])             if (sum[1] - sum[v] == n - cnt[v])               dpup[u] = 1 + salem[v] - (ok[u] ? cnt[u] : 0) + mxup[u] + dpup[v];             else               dpup[u] =                   1 + salem[v] - (ok[u] ? cnt[u] : 0) + max(mxup[u], dpup[v]);     for (auto u : g[v])       if (u != p)         if (c[u])           if (c[v])             if (sum[1] - sum[u] == n - cnt[u])               dip[u] = 1 + salem[u] + dpup[u] + mxdown[u];             else               dip[u] = 1 + salem[u] + max(dpup[u], mxdown[u]);     for (auto u : g[v])       if (u != p) dfsup(u, v);   }   int check(int mid) {     for (int i = 1; i <= n; ++i)       dip[i] = salem[i] = ok[i] = cnt[i] = dpdown[i] = dpup[i] = mxup[i] =           mxdown[i] = 0;     for (int i = 1; i <= n; ++i) c[i] = (a[i] >= mid);     dfsdown(1, 0);     dfsup(1, 0);     int mx = 0;     for (int i = 1; i <= n; ++i)       mx = max(max(mx, dip[i]), max(dpdown[i], dpup[i]));     return mx;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int k;     cin >> n >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     int l = 1, r = 1e6 + 85;     while (r - l > 1) {       int mid = (l + r) / 2;       if (check(mid) >= k)         l = mid;       else         r = mid;     }     cout << l << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int PI = acos(-1);   const int MAXN = 1e6;   unsigned long long comb(unsigned long long n, unsigned long long k) {     if (k > n) return 0;     unsigned long long u = 1;     for (unsigned long long i = 1; i <= k; i++) {       u *= n--;       u /= i;     }     return u;   }   int main() {     unsigned long long n, m, t;     while (cin >> n >> m >> t) {       unsigned long long ans = 0;       for (unsigned long long boys = 4; boys <= n; boys++) {         unsigned long long girls = t - boys;         if (girls > m) continue;         if (t < 1 + boys) break;         ans += comb(n, boys) * comb(m, girls);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, u, v, cnt, ans;   int t[1100000], nxt[1100000], to[1100000];   int a[1100000], b[1100000], c[1100000], f[1100000];   int vis[1100000];   void add(int u, int v) { nxt[cnt] = t[u], t[u] = cnt, to[cnt++] = v; }   void dfs(int x) {     vis[x] = true;     for (int e = t[x]; ~e; e = nxt[e]) {       int y = to[e];       to[e] = to[e ^ 1] = 0;       if (y) {         if (!vis[y]) dfs(y);         if (f[y])           a[++ans] = x, b[ans] = y, c[ans] = f[y], f[y] = 0;         else if (f[x])           a[++ans] = f[x], b[ans] = x, c[ans] = y, f[x] = 0;         else           f[x] = y;       }     }   }   int main() {     memset(t, 0xff, sizeof(t));     cin >> n >> m;     for (int i = 1; i <= m; ++i) cin >> u >> v, add(u, v), add(v, u);     vis[0] = true;     for (int i = 1; i <= n; ++i)       if (!vis[i]) dfs(i);     printf( %d n , ans);     for (int i = 1; i <= ans; ++i) printf( %d %d %d n , a[i], b[i], c[i]);     return 0;   }
#include <bits/stdc++.h>   const long double pi = acos(-1);   const long long mod = 1e9 + 7, N = 1e5 + 5;   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long q;     cin >> q;     while (q--) {       long long a, b;       cin >> a >> b;       if (a > b) {         if ((a % 2 == 0 && b % 2 == 0) || (a % 2 != 0 && b % 2 != 0))           cout << 1 << endl;         else           cout << 2 << endl;       } else if (a < b) {         if ((a % 2 == 0 && b % 2 == 0) || (a % 2 != 0 && b % 2 != 0))           cout << 2 << endl;         else           cout << 1 << endl;       } else         cout << 0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxint = 999999999;   string s;   int cnt[30];   int k;   int main() {     int i;     while (cin >> s) {       cin >> k;       int l = s.length();       if (l <= k) {         printf( 0 n );         printf(  n );         continue;       }       for (i = 0; i < l; i++) {         cnt[s[i] -  a ]++;       }       int Min, u;       while (1) {         if (k == 0) break;         Min = maxint;         u = -1;         for (i = 0; i < 26; i++) {           if (cnt[i] > 0 && cnt[i] < Min) {             Min = cnt[i];             u = i;           }         }         if (Min > k) {           k = 0;           cnt[u] -= k;         } else {           cnt[u] = 0;           k -= Min;         }       }       int ans = 0;       for (i = 0; i < 26; i++) {         if (cnt[i] > 0) ans++;       }       printf( %d n , ans);       for (i = 0; i < l; i++) {         if (cnt[s[i] -  a ] > 0) printf( %c , s[i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   #pragma Optimize( O3 )   using namespace std;   int n, x, a, b, y, m, ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     vector<int> v(n);     vector<int> a;     for (int i = 0; i < n; i++) cin >> v[i];     for (int i = 0; i < n; i += 2) a.push_back(v[i]);     for (int i = 1; i < n; i += 2) a.push_back(v[i]);     a.insert(a.end(), a.begin(), a.end());     long long sumtmp = 0;     for (int i = 0; i < (n + 1) / 2; i++) sumtmp += a[i];     long long sum = sumtmp;     for (int i = (n + 1) / 2; i < a.size(); i++) {       sumtmp += a[i] - a[i - (n + 1) / 2];       sum = max(sum, sumtmp);     }     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[4];     for (int i = 0; i < 4; i++) cin >> a[i];     sort(a, a + 4);     for (int i = 0; i < 2; i++)       if (a[i] + a[i + 1] > a[i + 2]) return 0 * printf( TRIANGLE );     for (int i = 0; i < 2; i++)       if (a[i] + a[i + 1] == a[i + 2]) return 0 * printf( SEGMENT );     return 0 * printf( IMPOSSIBLE );   }
#include <bits/stdc++.h>   const int N = 2e5 + 5;   const int MOD = 1e9 + 7;   using namespace std;   int n;   char str1[N], str2[N];   vector<int> lt[30], rt[30];   vector<pair<int, int> > ans;   int main() {     scanf( %d , &n);     scanf(  %s , str1);     scanf(  %s , str2);     for (int a = 0; a < n; a++) {       if (str1[a] ==  ? )         lt[26].push_back(a);       else         lt[(int)(str1[a] -  a )].push_back(a);       if (str2[a] ==  ? )         rt[26].push_back(a);       else         rt[(int)(str2[a] -  a )].push_back(a);     }     for (int a = 0; a < 26; a++) {       while (lt[a].size() > 0 && rt[a].size() > 0) {         ans.push_back({lt[a][lt[a].size() - 1] + 1, rt[a][rt[a].size() - 1] + 1});         lt[a].pop_back();         rt[a].pop_back();       }     }     int idx = 0;     while (lt[26].size() > 0 && idx < 26) {       while (lt[26].size() > 0 && rt[idx].size() > 0) {         ans.push_back(             {lt[26][lt[26].size() - 1] + 1, rt[idx][rt[idx].size() - 1] + 1});         lt[26].pop_back();         rt[idx].pop_back();       }       idx++;     }     idx = 0;     while (rt[26].size() > 0 && idx < 26) {       while (rt[26].size() > 0 && lt[idx].size() > 0) {         ans.push_back(             {lt[idx][lt[idx].size() - 1] + 1, rt[26][rt[26].size() - 1] + 1});         lt[idx].pop_back();         rt[26].pop_back();       }       idx++;     }     while (rt[26].size() > 0 && lt[26].size() > 0) {       ans.push_back(           {lt[26][lt[26].size() - 1] + 1, rt[26][rt[26].size() - 1] + 1});       lt[26].pop_back();       rt[26].pop_back();     }     printf( %d n , (int)ans.size());     for (auto v : ans) printf( %d %d n , v.first, v.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> a(n), b(n);     for (int i = 0; i < n; ++i) cin >> a[i];     iota(b.begin(), b.end(), 0);     sort(b.begin(), b.end(), [&](int i, int j) { return a[i] < a[j]; });     vector<vector<int>> c(n + 1);     for (int i = 0; i <= n; ++i) c[i].resize(n);     for (int i = 0; i < n; ++i)       for (int j = 0; j < a[b[i]]; ++j) c[(n + 1 + i - j) % (n + 1)][b[i]] = 1;     cout << n + 1 <<   n ;     for (int i = 0; i < n + 1; ++i, cout <<   n )       for (int j = 0; j < n; ++j) cout << c[i][j];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string n;     cin >> n;     int ind = -1;     int indn = -1;     int l = n.length();     for (int i = l - 1; i >= 0; i--) {       if (n[i] ==  0  || n[i] ==  2  || n[i] ==  4  || n[i] ==  6  ||           n[i] ==  8 ) {         if (n[i] < n[l - 1]) {           indn = i;         }       }     }     for (int i = 0; i < l - 1; i++) {       if (n[i] ==  0  || n[i] ==  2  || n[i] ==  4  || n[i] ==  6  ||           n[i] ==  8 ) {         if (n[i] > n[l - 1]) {           ind = i;         }       }     }     if (indn != -1) {       swap(n[indn], n[l - 1]);     } else if (indn == -1 && ind != -1) {       swap(n[ind], n[l - 1]);     } else if (indn == -1 && ind == -1) {       cout << -1;       return 0;     }     cout << n;   }