malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   vector<int> v;   vector<vector<int>> g;   int in[N], out[N], col[N], is[N], dp[18][N], depth[N], z;   struct node {     int l, r, id;     node(int a = 0, int b = 0, int c = 0) {       l = a;       r = b;       id = c;     }     bool operator<(const node& e) const {       int a = l / z, b = e.l / z;       if (a != b) return a < b;       if (a & 1) return r > e.r;       return r < e.r;     }   };   vector<node> q;   void dfs(int u, int p) {     dp[0][u] = p;     in[u] = v.size();     v.push_back(u);     for (int i = 1; i < 18; i++)       dp[i][u] = dp[i - 1][u] + 1 ? dp[i - 1][dp[i - 1][u]] : -1;     for (auto i : g[u])       if (i != p) depth[i] = depth[u] + 1, dfs(i, u);     out[u] = v.size();     v.push_back(u);   }   int lca(int a, int b) {     if (depth[a] < depth[b]) swap(a, b);     for (int i = 17; i + 1; i--)       if (depth[a] - (1 << i) >= depth[b]) a = dp[i][a];     if (a == b) return a;     for (int i = 17; i + 1; i--)       if (dp[i][a] != dp[i][b]) a = dp[i][a], b = dp[i][b];     return dp[0][a];   }   int main() {     int n;     scanf( %d , &n);     g.resize(n);     for (int i = 0; i < n; i++) scanf( %d , is + i);     for (int i = 0; i < n; i++) scanf( %d , col + i);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       g[--a].push_back(--b);       g[b].push_back(a);     }     dfs(0, -1);     scanf( %d , &n);     z = sqrt(v.size()) + 1;     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       --a;       --b;       if (in[a] > in[b]) swap(a, b);       q.push_back(node(in[a] + 1, in[b], i));     }     sort(q.begin(), q.end());     long long ans[N] = {}, temp = 0, freq[N] = {};     int l = 0, r = -1;     unordered_map<int, int> mp[2];     for (auto i : q) {       if (i.l - 1 == i.r) continue;       while (r < i.r) {         r++;         int a = is[v[r]];         int b = col[v[r]];         if (freq[v[r]]++) {           temp -= mp[!a][b];           mp[a][b]--;         } else {           temp += mp[!a][b];           mp[a][b]++;         }       }       while (r > i.r) {         int a = is[v[r]];         int b = col[v[r]];         if (--freq[v[r]]) {           temp += mp[!a][b];           mp[a][b]++;         } else {           temp -= mp[!a][b];           mp[a][b]--;         }         r--;       }       while (l < i.l) {         int a = is[v[l]];         int b = col[v[l]];         if (--freq[v[l]]) {           temp += mp[!a][b];           mp[a][b]++;         } else {           temp -= mp[!a][b];           mp[a][b]--;         }         l++;       }       while (l > i.l) {         l--;         int a = is[v[l]];         int b = col[v[l]];         if (freq[v[l]]++) {           temp -= mp[!a][b];           mp[a][b]--;         } else {           temp += mp[!a][b];           mp[a][b]++;         }       }       int LCA = lca(v[i.l - 1], v[i.r]);       int lol = mp[!is[LCA]][col[LCA]];       ans[i.id] = temp + lol;     }     for (int i = 0; i < q.size(); i++) printf( %lld n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int n, ls, tp, cx, yy, qq;   char s[64];   string ans, cur, st[55555][2], tt;   bool quot, found;   int main() {     scanf( %d n , &n);     tp = -1;     found = false;     qq = 0;     for (int _ = 0; _ < n; ++_) {       gets(s);       ls = strlen(s);       quot = false;       cur =   ;       for (int i = 0; i < ls; ++i)         if (quot) {           if (s[i] ==    )             quot = false;           else             cur += s[i];         } else {           if (s[i] ==    )             quot = true;           else if (s[i] !=    )             cur += s[i];         }       if (!cur.find( try )) {         tp += !found;         qq += found;       } else if (!cur.find( catch )) {         if (qq) {           --qq;           continue;         }         if (found) {           st[tp][0] =   ;           cx = 6;           while (cur[cx] !=  , ) st[tp][0] += cur[cx++];           ++cx;           st[tp][1] =   ;           while (cur[cx] !=  ) ) st[tp][1] += cur[cx++];           if (!tp) break;         }         --tp;       } else if (!cur.find( throw )) {         found = true;         yy = tp;         cx = 6;         tt =   ;         while (cur[cx] !=  ) ) tt += cur[cx++];       }     }     ans =  Unhandled Exception ;     for (int i = yy; i >= 0; --i)       if (st[i][0] == tt) {         ans = st[i][1];         break;       }     printf( %s , ans.c_str());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxL = 70;   int mod = 1e9 + 7;   long long mod1 = 1e9 + 7;   const int inf = 1.2e18;   const int maxn = 6e5 + 100;   const int baze = 330;   const int base = 3;   int from[maxn];   int to[maxn];   int w[maxn];   int dis[maxn];   int head[maxn];   int sdfgf[maxn];   int backup[maxn];   int chiz[maxn];   int eof, source = maxn - 1, sink = maxn - 2;   void add_edge(int u, int v, int W) {     from[eof] = u, to[eof] = v, w[eof] = W, sdfgf[eof] = head[u], head[u] = eof++;     swap(u, v);     W = 0;     from[eof] = u, to[eof] = v, w[eof] = W, sdfgf[eof] = head[u], head[u] = eof++;   }   bool bfs() {     int st = 0, en = 1;     chiz[0] = source;     memset(dis, 63, sizeof dis);     dis[source] = 0;     while (st < en) {       int v = chiz[st++];       for (int e = head[v]; ~e; e = sdfgf[e])         if (w[e] && dis[to[e]] > dis[v] + 1) {           dis[to[e]] = dis[v] + 1;           chiz[en++] = to[e];           if (to[e] == sink) return true;         }     }     return false;   }   int dfs(int v, int mn = 1000000) {     if (!mn || v == sink) return mn;     int ret = 0;     for (int &e = head[v]; ~e; e = sdfgf[e])       if (dis[to[e]] == dis[v] + 1) {         int x = dfs(to[e], min(mn, w[e]));         ret += x;         w[e] -= x;         w[e ^ 1] += x;         mn -= x;         if (mn == 0) break;       }     return ret;   }   int flow() {     memcpy(backup, head, sizeof head);     int ret = 0;     while (bfs()) {       ret += dfs(source);       memcpy(head, backup, sizeof head);     }     return ret;   }   int ar[60];   string t[maxn];   int pos[maxn];   int n;   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     memset(head, -1, sizeof head);     map<string, int> mp;     mp[ S ] = 0;     mp[ M ] = 1;     mp[ L ] = 2;     mp[ XL ] = 3;     mp[ XXL ] = 4;     mp[ XXXL ] = 5;     for (int i = 0; i < 6; i++) cin >> ar[i], add_edge(source, i, ar[i]);     cin >> n;     vector<int> vc;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       t[i] = s;       pos[i] = ((int)((s).size()));       if (s.find( , ) < ((int)((s).size()))) {         int x = s.find( , );         pos[i] = x;         vc.push_back(eof);         add_edge(mp[s.substr(0, x)], i + 10, 1);         add_edge(mp[s.substr(x + 1, ((int)((s).size())))], i + 10, 1);         add_edge(i + 10, sink, 1);       } else         vc.push_back(eof), add_edge(mp[s], sink, 1);     }     int ans = flow();     if (ans != n) return cout <<  NO  << endl, 0;     cout <<  YES  << endl;     int hlp = 0;     for (int x : vc) {       if (w[x] == 0)         cout << t[hlp].substr(0, pos[hlp]) <<   n ;       else         cout << t[hlp].substr(pos[hlp] + 1, ((int)((t[hlp]).size()))) <<   n ;       hlp++;     }   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long base, long long pow, long long mo) {     long long res = 1;     while (pow) {       if (pow % 2 != 0) res = (res * base) % mo;       base = (base * base) % mo;       pow /= 2;     }     return res;   }   long long inv(long long i) { return power(i, 1000000007 - 2, 1000000007); }   std::string str =  All Good Till Here ;   void solve() {     long long i, j, x, n;     cin >> n;     long long a[n], p[n];     for (long long c1 = 0; c1 < n; c1++) cin >> a[c1];     ;     for (long long i = 0; i < n; i++) {       p[a[i] - 1] = i;     }     long long ans = 0, max2 = 1;     for (long long i = 1; i < n; i++) {       if (p[i] > p[i - 1]) {         max2++;       } else {         ans = max(max2, ans);         max2 = 1;       }     }     ans = max(max2, ans);     cout << n - ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tt;     tt = 1;     while (tt--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     bitset<6> a(n);     string s = a.to_string();     swap(s[1], s[5]);     swap(s[2], s[3]);     bitset<6> b(s);     cout << static_cast<int>(b.to_ulong()) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int ans[51][6] = {       0,  0,  0,  0,  0, 0, 0,  0,  0,  0,  0, 0, 2,  1,  0,  0,  0, 0,       3,  2,  0,  0,  0, 0, 4,  3,  0,  0,  0, 0, 5,  3,  0,  0,  0, 0,       6,  5,  0,  0,  0, 0, 7,  6,  0,  0,  0, 0, 8,  6,  5,  4,  0, 0,       9,  5,  0,  0,  0, 0, 10, 7,  0,  0,  0, 0, 11, 9,  0,  0,  0, 0,       12, 6,  4,  1,  0, 0, 13, 4,  3,  1,  0, 0, 14, 5,  3,  1,  0, 0,       15, 14, 0,  0,  0, 0, 16, 15, 13, 4,  0, 0, 17, 14, 0,  0,  0, 0,       18, 11, 0,  0,  0, 0, 19, 6,  2,  1,  0, 0, 20, 17, 0,  0,  0, 0,       21, 19, 0,  0,  0, 0, 22, 21, 0,  0,  0, 0, 23, 18, 0,  0,  0, 0,       24, 23, 22, 17, 0, 0, 25, 22, 0,  0,  0, 0, 26, 6,  2,  1,  0, 0,       27, 5,  2,  1,  0, 0, 28, 25, 0,  0,  0, 0, 29, 27, 0,  0,  0, 0,       30, 6,  4,  1,  0, 0, 31, 28, 0,  0,  0, 0, 32, 22, 2,  1,  0, 0,       33, 20, 0,  0,  0, 0, 34, 27, 2,  1,  0, 0, 35, 33, 0,  0,  0, 0,       36, 25, 0,  0,  0, 0, 37, 5,  4,  3,  2, 1, 38, 6,  5,  1,  0, 0,       39, 35, 0,  0,  0, 0, 40, 38, 21, 19, 0, 0, 41, 38, 0,  0,  0, 0,       42, 41, 20, 19, 0, 0, 43, 42, 38, 37, 0, 0, 44, 43, 18, 17, 0, 0,       45, 44, 42, 41, 0, 0, 46, 45, 26, 25, 0, 0, 47, 42, 0,  0,  0, 0,       48, 47, 21, 20, 0, 0, 49, 40, 0,  0,  0, 0, 50, 49, 24, 23, 0, 0,   };   int main() {     int k;     cin >> k;     for (int i = 0; i < k; i++) {       int found = 0;       for (int j = 0; j < 6; j++)         if (ans[k][j] == i + 1) found = 1;       cout << found <<    ;     }     cout << endl;     for (int i = 0; i < k; i++) cout <<  1  ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tux;     cin >> tux;     int foo, bar, baz, quz, pur, oo;     foo = bar = baz = 0;     quz = 1;     while (tux) {       cin >> pur;       foo += pur;       bar++;       if (foo * quz > bar * baz) {         baz = foo;         quz = bar;       }       tux--;     }     cout.precision(5);     cout << fixed << (baz * 1. / quz);     return 0;   }
#include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef long double ld;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;   typedef vector<int> vi;   typedef vector<ll> vl;   typedef vector<pii> vii;   typedef vector<vi> vvi;   typedef vector<pll> vll;   typedef vector<vl> vvl;      #define fori(i, n) for (int i = 0; i < n; i++)   #define ford(i, n) for (int i = n - 1; i >= 0; i--)   #define rep(i, a, b) for (int i = a; i <= b; i++)   #define repd(i, a, b) for (int i = a; i >= b; i--)   #define trav(x, a) for (auto &x : a)   #define all(x) (x).begin(), (x).end()   #define pb push_back   #define eb emplace_back   #define endl   n    #define sz(a) (int)(a).size()   #define fi first   #define se second      clock_t time_p = clock();   void time_taken()   {       time_p = clock() - time_p;       cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }      const ll mod = 1e9 + 7;   const ll INF = 1e18;      int main()   {       ios_base::sync_with_stdio(false), cin.tie(nullptr);          int n, d;       cin >> n >> d;          vi a(n);       fori(i, n) cin >> a[i];          vector<vector<ld>> dp(n + 1, vector<ld>(10, -1));       vvi prv(n + 1, vi(10));       vvi taken(n + 1, vi(10));       dp[0][1] = 0;          for (int i = 0; i < n; i++)       {           for (int j = 0; j < 10; j++)           {               if (dp[i][j] == -1)                   continue;               int to = (j * a[i]) % 10;               ld maybe = dp[i][j] + log2l(a[i]);               if (maybe > dp[i + 1][to])               {                   dp[i + 1][to] = maybe;                   taken[i + 1][to] = 1;                   prv[i + 1][to] = j;               }                  to = j;               maybe = dp[i][j];               if (maybe > dp[i + 1][to])               {                   dp[i + 1][to] = maybe;                   taken[i + 1][to] = 0;                   prv[i + 1][to] = j;               }           }       }          if (dp[n][d] == -1)       {           cout <<  -1  << endl;           return 0;       }          int i = n, j = d;          vi ans;       while (i)       {           if (taken[i][j])           {               ans.pb(a[i - 1]);           }           j = prv[i][j];           i--;       }          if(sz(ans) == 0){           cout << -1 << endl;           return 0;       }          cout << sz(ans) << endl;       for (int x : ans)       {           cout << x <<    ;       }       cout << endl;          time_taken();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, sz, timer;   int p[1000005];   vector<int> v[1000005];   int tin[1000005], tout[1000005];   int t[4000005], tt[4000005];   int depth[1000005];   int a[1000005];   pair<int, int> q[1000005];   bool used[1000005];   void dfs(int x, int y = 0) {     used[x] = true;     tin[x] = ++timer;     depth[x] = depth[y] + 1;     for (int i = 0; i < v[x].size(); ++i) {       int to = v[x][i];       dfs(to, x);     }     tout[x] = timer;     return;   }   void update(int x, int y) {     x += sz - 1;     t[x] = y;     x >>= 1;     while (x) {       t[x] = max(t[x + x], t[x + x + 1]);       x >>= 1;     }     return;   }   int get(int l, int r, int ll, int rr, int x) {     if (l > r || ll > r || l > rr || ll > rr) return 0;     if (l >= ll && r <= rr) return t[x];     int mid = (l + r) >> 1;     return max(get(l, mid, ll, rr, x + x), get(mid + 1, r, ll, rr, x + x + 1));   }   void update2(int x, int y) {     x += sz - 1;     tt[x] = y;     x >>= 1;     while (x) {       tt[x] = max(tt[x + x], tt[x + x + 1]);       x >>= 1;     }     return;   }   int get_pred(int x) {     if (x == p[x]) return x;     return p[x] = get_pred(p[x]);   }   void update_val(int x) {     int val = get(1, sz, tin[x], tout[x], 1) - depth[x] + 1;     update2(x, val);     return;   }   void add_vertex(int x) {     for (int i = 0; i < v[x].size(); ++i) {       int to = v[x][i];       update2(to, 0);       to = get_pred(to);       p[to] = x;     }     update(tin[x], depth[x]);     update_val(x);     return;   }   void del_vertex(int x) {     update(tin[x], 0);     x = get_pred(x);     update_val(x);     return;   }   int main(int argc, const char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     q[0] = {1e9, n + 1};     for (int i = n; i > 0; --i) {       while (sz > 0 && q[sz].first <= a[i]) --sz;       v[q[sz].second].push_back(i);       q[++sz] = {a[i], i};     }     for (int i = n + 1; i > 0; --i)       if (!used[i]) dfs(i);     for (int i = 1; i <= n + 1; ++i) p[i] = i;     sz = 1;     while (sz < n + 1) sz += sz;     for (int i = 1; i <= m; ++i) {       add_vertex(i);     }     cout << tt[1] <<    ;     for (int i = m + 1; i <= n; ++i) {       add_vertex(i);       del_vertex(i - m);       cout << tt[1] <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   int sta[1000001], head, ans[1000001];   char s[1000001];   int main() {     int ans1 = 0, ans2 = 1;     scanf( %s , s);     for (int i = 0; s[i]; ++i) {       if (s[i] ==  ) ) {         if (!head) continue;         head--;         ans[i] = i - sta[head] + 1 + ans[sta[head] - 1];         if (ans1 == ans[i])           ans2++;         else if (ans1 < ans[i]) {           ans1 = ans[i];           ans2 = 1;         }       } else         sta[head++] = i;     }     printf( %d %d , ans1, ans2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n;   int a[200004];   int main() {     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < 2 * n; i++) cin >> a[i];       sort(a, a + 2 * n);       cout << a[n] - a[n - 1] <<   n ;     }     cin >> t;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T, n, a[30005], b[30005];   long long sum[2];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       a[n + 1] = 0;       for (int i = 1; i <= n + 1; i++) b[i] = a[i] - a[i - 1];       sum[0] = sum[1] = 0;       for (int i = 2; i <= n; i++) {         if (b[i] > 0)           sum[0] += b[i];         else           sum[1] -= b[i];       }       if (b[1] >= sum[1] && -b[n + 1] >= sum[0]) {         printf( YES n );       } else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool g[205][205];   struct coor {     int x, y;   };   vector<int> ans;   int a[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1};   coor Max, Min;   int w, h;   void dfs(int x, int y) {     g[x][y] = 1;     for (int i = 0; i < 8; i++) {       coor c;       c.x = x + a[i][0];       c.y = y + a[i][1];       if (c.x >= 0 && c.x <= w && c.y >= 0 && c.y <= h) {         if (c.x >= Max.x && c.y >= Max.y) Max = c;         if (c.x <= Min.x && c.y <= Min.y) Min = c;         if (g[c.x][c.y] == 0) dfs(c.x, c.y);       }     }   }   void out() {     int i, j;     for (i = 0; i <= w; i++) {       for (j = 0; j <= h; j++) {         printf( %d , g[i][j]);       }       printf(  n );     }     printf(  n );   }   int main() {     int i, j, n, x1, x2, y1, y2;     scanf( %d%d%d , &w, &h, &n);     w = w + w;     h = h + h;     ans.clear();     memset(g, 0, sizeof(g));     for (i = 0; i <= w; i++) g[i][0] = g[i][h] = 1;     for (i = 0; i <= h; i++) g[0][i] = g[w][i] = 1;     for (j = 0; j < n; j++) {       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       x1 += x1;       x2 += x2;       y1 += y1;       y2 += y2;       if (x1 == x2)         for (i = y1; i <= y2; i++) g[x1][i] = 1;       else         for (i = x1; i <= x2; i++) g[i][y1] = 1;     }     for (i = 0; i <= w; i++)       for (j = 0; j <= h; j++) {         if (g[i][j] == 0) {           Max.x = Max.y = -1;           Min.y = Min.x = 1000;           dfs(i, j);           ans.push_back((Max.x - Min.x) * (Max.y - Min.y) / 4);         }       }     sort(ans.begin(), ans.end());     for (i = 0; i < ans.size() - 1; i++) printf( %d  , ans[i]);     printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000, M = 1000000007, D3 = (M + 1) / 3;   int T, n, m;   int pd[N + 5], pr[N], pn, phi[N + 5];   int f[N + 5], s0[N + 5], s1[N + 5], s2[N + 5];   void init() {     phi[1] = 1;     for (int i = 2; i <= N; i++) {       if (!pd[i]) phi[i] = i - 1, pr[++pn] = i;       for (int j = 1; j <= pn && i * pr[j] <= N; j++) {         pd[i * pr[j]] = pr[j];         if (i % pr[j] == 0) {           phi[i * pr[j]] = phi[i] * pr[j];           break;         } else           phi[i * pr[j]] = phi[i] * phi[pr[j]];       }     }     for (int d = 1; d <= N; d++)       for (int k = d; k <= N; k += d) f[k] += d * phi[k / d];     for (int L = 1; L <= N; L++) {       f[L] =           (((long long)L * L - L - L) % M * L % M -            (long long)(L + 1) * L % M * L % M +            (long long)L * (L + 1) % M * (L + L + 1) % M * D3 % M + 2LL * f[L]) %           M;       if (f[L] < 0) f[L] += M;     }     for (int i = 1; i <= N; i++) {       s0[i] = (s0[i - 1] + (long long)f[i]) % M;       s1[i] = (s1[i - 1] + (long long)i * f[i]) % M;       s2[i] = (s2[i - 1] + (long long)i * i % M * f[i]) % M;     }   }   int main() {     init();     for (scanf( %d , &T); T--;) {       scanf( %d%d , &n, &m);       if (n > m) swap(n, m);       long long ans = (long long)(n + 1) * (m + 1) % M * s0[n] % M;       ans -= (long long)(n + m + 2) * s1[n] % M;       ans += s2[n];       ans = (ans % M + M) % M;       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int n, m;   vector<int> tr[1000005];   vector<int> vr[1000005];   pair<int, int> pr[1000005];   int high;   long long team[1000005], ir[1000005];   int main() {     scanf( %d %d , &n, &m);     int x, y;     for (int i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       if (x < y) swap(x, y);       vr[x].push_back(y);     }     for (int i = 1; i < n + 1; i++) {       scanf( %d , &x);       for (int j = 0; j < x; j++) {         scanf( %d , &y);         tr[i].push_back(y);         high = max(high, y);       }     }     while (1) {       int tot = 0;       for (int i = 1; i < high + 1; i++) team[i] = rng() % 2 + 1;       for (int i = 1; i < n + 1; i++) {         ir[i] = tr[i][rng() % tr[i].size()];         for (int j = 0; j < vr[i].size(); j++) {           if (team[ir[vr[i][j]]] != team[ir[i]]) tot++;         }       }       if (tot >= m / 2 + (m % 2)) break;     }     for (int i = 1; i < n + 1; i++) printf( %d  , ir[i]);     printf(  n );     for (int i = 1; i < high + 1; i++) printf( %d  , team[i]);   }
#include <bits/stdc++.h>   using namespace std;   int a[200001];   int b[200000];   int c[200001];   int main() {     int n, i, j;     cin >> n;     map<int, int> m;     for (i = 0; i < n; i++) {       cin >> b[i];       m[b[i]]++;       a[b[i]] = 1;     }     vector<int> v;     for (i = 1; i <= n; i++) {       if (a[i] == 0) {         v.push_back(i);       }     }     sort(v.begin(), v.end());     cout << v.size() << endl;     int p = 0;     for (i = 0; i < n; i++) {       if (c[b[i]] == 1) {         cout << v[p] <<    ;         p++;         c[b[i]] = 1;         m[b[i]]--;       } else {         if (m[b[i]] == 1) {           cout << b[i] <<    ;         } else if (m[b[i]] > 1) {           if (v[p] < b[i]) {             cout << v[p] <<    ;             m[b[i]]--;             p++;           } else {             cout << b[i] <<    ;             c[b[i]] = 1;             m[b[i]]--;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class segtree {    public:     int val[(1 << 20) * 2];     int le[(1 << 20) * 2];     int ri[(1 << 20) * 2];     void update(int pos, int x) {       val[pos + (1 << 20) - 1] = 0;       le[pos + (1 << 20) - 1] = 1 - x;       ri[pos + (1 << 20) - 1] = x;     }     void up() {       for (int i = (1 << 20) - 2; i >= 0; i--) {         int add = min(le[i * 2 + 1], ri[i * 2 + 2]);         val[i] = val[i * 2 + 1] + val[i * 2 + 2] + add;         le[i] = le[i * 2 + 1] + le[i * 2 + 2] - add;         ri[i] = ri[i * 2 + 1] + ri[i * 2 + 2] - add;       }     }     pair<int, pair<int, int> > query(int a, int b, int k, int l, int r) {       pair<int, pair<int, int> > p = make_pair(0, make_pair(0, 0));       if (r < a || b < l) return p;       if (a <= l && r <= b) {         return make_pair(val[k], make_pair(le[k], ri[k]));       }       pair<int, pair<int, int> > x = query(a, b, k * 2 + 1, l, (l + r) / 2);       pair<int, pair<int, int> > y = query(a, b, k * 2 + 2, (l + r) / 2 + 1, r);       int z = min(x.second.first, y.second.second);       return make_pair(x.first + y.first + z,                        make_pair(x.second.first + y.second.first - z,                                  x.second.second + y.second.second - z));     }   } seg;   char ss[1000005];   int main() {     scanf( %s , &ss);     int n = strlen(ss);     for (int i = 0; i < n; i++) {       seg.update(i, (ss[i] ==  ) ));     }     seg.up();     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int a, b;       scanf( %d %d , &a, &b);       a--;       b--;       printf( %d n , seg.query(a, b, 0, 0, (1 << 20) - 1).first * 2);     }   }