malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     if (abs(a + c - b - d) > 1) {       cout <<  NO n ;     } else {       vector<int> v(a + b + c + d);       if (a + c > b + d) {         for (int i = 0; i < v.size(); i += 2) {           if (a) {             v[i] = 0;             a--;           } else {             v[i] = 2;             c--;           }         }         for (int i = 1; i < v.size(); i += 2) {           if (b) {             v[i] = 1;             b--;           } else {             v[i] = 3;             d--;           }         }       } else {         for (int i = 1; i < v.size(); i += 2) {           if (a) {             v[i] = 0;             a--;           } else {             v[i] = 2;             c--;           }         }         for (int i = 0; i < v.size(); i += 2) {           if (b) {             v[i] = 1;             b--;           } else {             v[i] = 3;             d--;           }         }       }       bool check = true;       for (int i = 0; i < (int)v.size() - 1; i++) {         if (abs(v[i] - v[i + 1]) != 1) {           check = false;           break;         }       }       if (a + c == b + d && check == false) {         for (int i = 0; i < (int)v.size() - 1; i += 2) {           swap(v[i], v[i + 1]);         }         check = true;         for (int i = 0; i < (int)v.size() - 1; i++) {           if (abs(v[i] - v[i + 1]) != 1) {             check = false;             break;           }         }       }       if (check) {         cout <<  YES n ;         for (int i : v) cout << i <<    ;         cout <<   n ;       } else         cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 200005;   int n, m, b[N];   char a[N], A[N];   int main() {     scanf( %d%d%s , &n, &m, a);     memset(b, 0x3f, sizeof(b));     for (int i = 0; i < n; i++) {       int l = (i - 1 + n) % n, r = (i + 1) % n;       if (a[i] == a[r]) {         for (int j = l, k = 1;              a[j] != a[(j + 1) % n] && a[j] != a[(j - 1 + n) % n];              j = (j - 1 + n) % n, k++) {           if (k < b[j]) {             b[j] = k;             if (k <= m) A[j] = a[i];           }         }         for (int j = (r + 1) % n, k = 1;              a[j] != a[(j - 1 + n) % n] && a[j] != a[(j + 1) % n];              j = (j + 1) % n, k++) {           if (k < b[j]) {             b[j] = k;             if (k <= m) A[j] = a[i];           }         }       }     }     for (int i = 0; i < n; i++) {       if (b[i] <= m)         printf( %c , A[i]);       else if (a[i] == a[(i + 1) % n] || a[i] == a[(i - 1 + n) % n]) {         printf( %c , a[i]);       } else {         if (m & 1)           printf( %c ,  BW [a[i] ==  B ]);         else           printf( %c , a[i]);       }     }   }
#include <bits/stdc++.h>   using namespace std;   string S;   vector<vector<vector<int> > > cc;   int dp(int idx, int d, int s) {     int &ret = cc[idx][d][s];     if (ret != -1) return ret;     if (idx == S.size() / 2) {       if (S.size() % 2) {         int x = S[idx] -  0 ;         if ((10 * d + x - s) < 0 || (x - s) % 2)           return 0;         else           return 1;       } else         return d == s;     }     ret = 0;     for (int i = idx == 0; i <= 18; i++) {       int x = S[idx] -  0 ;       if ((s + i) % 10 != x) continue;       int y = S[S.size() - 1 - idx] -  0 ;       if (10 * d + y - i != 0 && 10 * d + y - i != 1) continue;       ret |= dp(idx + 1, 10 * d + y - i, i + s >= 10);     }     return ret;   }   vector<int> A;   void dfs(int idx, int d, int s) {     if (idx == S.size() / 2) {       if (S.size() % 2) {         int x = S[idx] -  0 ;         A[idx] = (10 * d + x - s) / 2;         return;       } else         return;     }     for (int i = idx == 0; i <= 18; i++) {       int x = S[idx] -  0 ;       if ((s + i) % 10 != x) continue;       int y = S[S.size() - 1 - idx] -  0 ;       if (10 * d + y - i != 0 && 10 * d + y - i != 1) continue;       if (dp(idx + 1, 10 * d + y - i, i + s >= 10)) {         A[idx] = i / 2;         A[S.size() - 1 - idx] = i - i / 2;         dfs(idx + 1, 10 * d + y - i, i + s >= 10);         return;       }     }   }   int main() {     cin >> S;     reverse(S.begin(), S.end());     cc = vector<vector<vector<int> > >(         S.size(), vector<vector<int> >(2, vector<int>(2, -1)));     if (dp(0, 0, 0)) {       A.resize(S.size());       dfs(0, 0, 0);       reverse(A.begin(), A.end());       for (int i = 0; i < A.size(); i++) {         printf( %d , A[i]);       }       return 0;     }     if (S[S.size() - 1] !=  1 ) {       printf( 0 );       return 0;     }     S.erase(S.end() - 1);     cc = vector<vector<vector<int> > >(         S.size() + 1, vector<vector<int> >(2, vector<int>(2, -1)));     if (dp(0, 1, 0)) {       A.resize(S.size());       dfs(0, 1, 0);       reverse(A.begin(), A.end());       for (int i = 0; i < A.size(); i++) {         printf( %d , A[i]);       }       return 0;     }     printf( 0 );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100105;   const double eps = 1e-6;   long double x1, y1_, x2, y2, mx, my, vx, vy, d, L, ans = 1e16;   vector<pair<long double, int> > V;   int X[N], Y[N], R[N], n, s = 0;   long double check(int k, long double t, int op) {     return ((sqrt(d * d + t * t) + op * R[k]) *             (sqrt(d * d + t * t) + op * R[k])) -            ((X[k] - mx - vx * t) * (X[k] - mx - vx * t)) -            ((Y[k] - my - vy * t) * (Y[k] - my - vy * t));   }   long double BI(int k, int op) {     long double l = -1e12, r = 1e12, mid, c = check(k, l, op), cc;     while (r - l > eps) {       mid = (l + r) / 2, cc = check(k, mid, op);       (c > 0 && cc > 0 || c < 0 && cc < 0) ? l = mid : r = mid;     }     return (l + r) / 2;   }   int main() {     scanf( %Lf%Lf%Lf%Lf%d , &x1, &y1_, &x2, &y2, &n);     for (int i = (1); i <= (n); ++i) scanf( %d%d%d , &X[i], &Y[i], &R[i]);     mx = (x1 + x2) / 2, my = (y1_ + y2) / 2,     L = sqrt(((x1 - x2) * (x1 - x2)) + ((y1_ - y2) * (y1_ - y2))),     vx = (y1_ - y2) / L, vy = (x2 - x1) / L, d = L / 2;     for (int i = (1); i <= (n); ++i) {       long double l = BI(i, 1), r = BI(i, -1);       if (l > r) swap(l, r);       V.push_back(make_pair(l - eps, -1)), V.push_back(make_pair(r + eps, 1));     }     V.push_back(make_pair(0, 0));     sort((V).begin(), (V).end());     for (int i = 0; i < V.size(); i++) {       s += V[i].second;       if (s == 0 || V[i].second == -1 && s == -1)         ans = min(ans, sqrt(((V[i].first) * (V[i].first)) + ((d) * (d))));     }     printf( %.12Lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const double eps = 1e-8;   const double pi = acos(-1.0);   int n, m;   char a[110], b[110], c[110];   int d[26];   int main() {     srand(time(NULL));     scanf( %d%d%s%s , &n, &m, a, b);     int la = strlen(a), lb = strlen(b);     int flag = 1;     for (int i = 0; i < lb; i++)       if (b[i] ==  1 ) {         for (int j = 0; j < la; j++)           if (c[i + j] == 0 || c[i + j] == a[j]) {             c[i + j] = a[j];           } else             flag = 0;         if (flag == 0) break;       }     if (flag) {       for (int i = 0; i < m; i++) d[i] = i;       for (int i = 0; i < lb; i++)         if (b[i] ==  0 ) {           int done = 0;           for (int j = 0; j < la; j++)             if (c[i + j] == 0) {               random_shuffle(d, d + m);               for (int k = 0; k < m; k++) {                 if (d[k] +  a  != a[j]) {                   c[i + j] = d[k] +  a , done = 1;                   break;                 }               }             } else if (c[i + j] != a[j]) {               done = 1;               break;             }           if (!done) {             flag = 0;             break;           }         }     }     for (int i = 0; i < n; i++)       if (c[i] == 0) c[i] =  a ;     if (flag)       puts(c);     else       puts( No solution );     return 0;   }
#include <bits/stdc++.h>   long long a[1001];   using namespace std;   int main() {     long long n, cnt = 0;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 0) {         cnt++;       }       if (n == 1) {         if (a[i] == 0) {           cout <<  NO ;           return 0;         } else {           cout <<  YES ;           return 0;         }       }     }     if (cnt >= 0 && cnt != 1) {       cout <<  NO ;       return 0;     } else {       cout <<  YES ;       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> p(n / 2);     for (int i = 0; i < n / 2; i++) {       cin >> p[i];     }     sort(p.begin(), p.end());     int sum1 = 0, sum2 = 0;     for (int i = 0; i < n / 2; i++) {       sum1 += abs(p[i] - i * 2 - 1);       sum2 += abs(p[i] - i * 2 - 2);     }     cout << min(sum1, sum2) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gi() {     int x = 0, c = getchar();     bool f = 0;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = 1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c & 15);     return f ? -x : x;   }   const int N = 300005;   const int mod = 998244353;   int a[N];   int qpow(int a, int b) {     int t = 1;     while (b) {       if (b & 1) t = 1ll * t * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return t;   }   bool cmp(const int &a, const int &b) { return a < b; }   int main() {     int n = gi();     for (int i = 1; i <= (n << 1); ++i) a[i] = gi();     sort(a + 1, a + (n << 1) + 1, cmp);     int fac = 1;     for (int i = 1; i <= n; ++i) fac = 1ll * fac * i % mod;     int faci = qpow(fac, mod - 2);     for (int i = n + 1; i <= (n << 1); ++i) fac = 1ll * fac * i % mod;     int ans = 0;     for (int i = 1; i <= n; ++i) {       ans += a[n + i] - a[i];       if (ans >= mod) ans -= mod;     }     printf( %d n , 1ll * fac * faci % mod * faci % mod * ans % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) { return a < b ? a : b; }   long long max(long long a, long long b) { return a > b ? a : b; }   int read() {     int x = 0, w = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     return x * w;   }   void bmax(long long &t1, long long t2) { t1 = max(t1, t2); }   void bmin(long long &t1, long long t2) { t1 = min(t1, t2); }   const int N = 2e5 + 10;   const long long INF = 1e16;   struct Node {     long long mx, mn, ans;     Node(long long _mx = -INF, long long _mn = INF, long long _ans = -INF)         : mx(_mx), mn(_mn), ans(_ans) {}     Node operator+(const Node &tmp) const {       Node res = Node(mx, mn);       res.ans = max(tmp.mx - mn, max(ans, tmp.ans));       bmax(res.mx, tmp.mx);       bmin(res.mn, tmp.mn);       return res;     }   };   int n, m;   long long h[N], s[N];   struct SegmentTree {     Node tr[N << 2];     void Build(int pos, int l, int r) {       if (l == r) {         tr[pos].mx = h[l] + s[l - 1];         tr[pos].mn = s[l - 1] - h[l];         tr[pos].ans = -INF;         return;       }       int mid = (l + r) >> 1;       Build(pos << 1, l, mid);       Build(pos << 1 | 1, mid + 1, r);       tr[pos] = tr[pos << 1] + tr[pos << 1 | 1];     }     Node Query(int pos, int L, int R, int l, int r) {       if (R < l || L > r) return Node();       if (l <= L && R <= r) return tr[pos];       int mid = (L + R) >> 1;       Node res1 = Query(pos << 1, L, mid, l, r),            res2 = Query(pos << 1 | 1, mid + 1, R, l, r);       Node res = res1 + res2;       return res;     }   } Tr;   int main() {     n = read();     m = read();     s[0] = 0;     for (int i = 1; i <= n; i++) s[i] = read(), s[i + n] = s[i];     for (int i = 1; i <= n; i++) h[i] = read() * 2, h[n + i] = h[i];     for (int i = 1; i <= 2 * n; i++) s[i] += s[i - 1];     Tr.Build(1, 1, 2 * n);     while (m--) {       int l = read(), r = read();       Node ans;       if (l <= r)         ans = Tr.Query(1, 1, 2 * n, r + 1, l + n - 1);       else         ans = Tr.Query(1, 1, 2 * n, r + 1, l - 1);       printf( %lld n , ans.ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int c[1005][1005], quadratic = 0, single_x = 0, single_y = 0,                                cnstnt = 0;   void calc_time_function(long long int n, long long int m) {     long long int i, j, centr_x, centr_y;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         centr_x = i * 4 + 2LL;         centr_y = j * 4 + 2LL;         quadratic += c[i][j];         cnstnt += c[i][j] * (centr_x * centr_x + centr_y * centr_y);         single_x += (2 * c[i][j] * centr_x);         single_y += (2 * c[i][j] * centr_y);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long int i, j, t, n, m, k, l, r, temp, left, right, mini, maxi, flag,         leftthird, rightthird, x, y;     cin >> n >> m;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) cin >> c[i][j];     mini = 1e18;     ;     calc_time_function(n, m);     for (i = 0; i <= n; i++) {       for (j = 0; j <= m; j++) {         x = i * 4;         y = j * 4;         temp = (x * x + y * y) * quadratic - x * single_x - y * single_y + cnstnt;         if (temp < mini) {           mini = temp;           left = i;           right = j;         }       }     }     cout << mini << endl;     cout << left <<     << right << endl;     return 0;   }
#include <bits/stdc++.h>   const int INFI = (1 << 29);   const long long INFL = (1LL << 62);   using namespace std;   void solve() {     long long a, n, m;     cin >> a >> n >> m;     bitset<2010> rain;     vector<long long> v(m + 1);     vector<pair<long long, long long> > umb(a + 1, {INFL, 0});     for (long long i = 0; i < n; i++) {       long long l, r;       cin >> l >> r;       for (long long j = l; j <= r - 1; j++) rain[j] = 1;     }     for (long long i = 1; i <= m; i++) {       long long l, r;       cin >> l >> r;       v[i] = r;       umb[l] = min(umb[l], {r, i});     }     vector<vector<long long> > dp(a + 1, vector<long long>(m + 1, INFL));     dp[0][0] = 0;     for (long long i = 0; i < a; i++) {       for (long long j = 0; j <= m; j++) {         if (dp[i][j] == INFL) continue;         if (umb[i].first != INFL)           dp[i + 1][umb[i].second] =               min(dp[i + 1][umb[i].second], dp[i][j] + umb[i].first);         if (j) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + v[j]);         if (!rain[i]) dp[i + 1][0] = min(dp[i + 1][0], dp[i][j]);       }     }     long long r = *min_element(dp[a].begin(), dp[a].end());     if (r == INFL) r = -1;     cout << r <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int c1, c2, c3, c4, n, m, bus[1009], tre[1009], x, z1, z, l, l1, y;   int main() {     cin >> c1 >> c2 >> c3 >> c4;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> bus[i];       if (l == 0) {         if (x + bus[i] * c1 < x + c2)           x += bus[i] * c1;         else           x += c2;         if (x > c3) x = c3, l = 1;       }     }     for (int i = 1; i <= m; i++) {       cin >> tre[i];       if (l1 == 0) {         if (y + tre[i] * c1 < y + c2)           y += tre[i] * c1;         else           y += c2;         if (y > c3) y = c3, l1 = 1;       }     }     x = min(x + y, c4);     cout << x;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> tree[1 << 20];   long long a[1 << 20], goal[1 << 20];   vector<long long> ans;   void dfs(long long v, long long cnt1 = 0, long long cnt2 = 0,            long long par = -1) {     for (long long i = 0; i < cnt1; i++) {       a[v] = !a[v];     }     if (goal[v] != a[v]) {       cnt1++;       ans.push_back(v);     }     for (long long i = 0; i < tree[v].size(); i++) {       if (tree[v][i] != par) dfs(tree[v][i], cnt2, cnt1, v);     }   }   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n - 1; i++) {       long long temp, temp1;       cin >> temp >> temp1;       tree[temp].push_back(temp1);       tree[temp1].push_back(temp);     }     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) cin >> goal[i];     dfs(1);     cout << ans.size() <<   n ;     for (long long i = 0; i < ans.size(); i++) cout << ans[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int ara[100005];   int pri[100005];   vector<int> jog[2 * 100005], biyog[2 * 100005];   map<pair<int, int>, int> dp1, dp2;   int cnt1(int x, int y) {     if (y == m + 1) return x;     if (dp1.find({x, y}) != dp1.end()) return dp1[{x, y}];     int val = x - y + 100005;     int idx =         lower_bound(biyog[val].begin(), biyog[val].end(), y) - biyog[val].begin();     if (idx == biyog[val].size()) return dp1[{x, y}] = min(n, x + m + 1 - y);     int j = biyog[val][idx];     assert(j != y);     return dp1[{x, y}] = cnt1(ara[j], pri[j]);   }   int cnt2(int x, int y) {     if (y == m + 1) return x;     if (dp2.find({x, y}) != dp2.end()) return dp2[{x, y}];     int val = x + y;     int idx = lower_bound(jog[val].begin(), jog[val].end(), y) - jog[val].begin();     if (idx == jog[val].size()) return dp2[{x, y}] = max(1, x - m - 1 + y);     int j = jog[val][idx];     assert(j != y);     return dp2[{x, y}] = cnt2(ara[j], pri[j]);   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d , ara + i);     if (n == 1) {       printf( 0 n );       return 0;     }     for (int i = 1; i <= m; i++) {       jog[ara[i] + i].push_back(i);       biyog[ara[i] - i + 100005].push_back(i);     }     for (int i = 0; i < 2 * 100005; i++) sort(jog[i].begin(), jog[i].end());     for (int i = 0; i < 2 * 100005; i++) sort(biyog[i].begin(), biyog[i].end());     for (int i = m; i; i--) {       if (ara[i] == ara[i + 1])         pri[i] = pri[i + 1];       else         pri[i] = i + 1;     }     long long ans = 0;     for (int i = 1; i < n; i++) ans += cnt1(i, 0) - i;     for (int i = 2; i <= n; i++) ans += i - cnt2(i, 0);     ans += n;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6, inf = 1e9 + 2;   pair<int, int> a[N + 2], b[N + 2], aa[N + 2], bb[N + 2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, c, d;     cin >> n >> c >> d;     int p = 0, q = 0;     for (int i = 1; i <= n; i++) {       int x, y;       char c;       cin >> x >> y >> c;       if (c ==  C )         a[++p] = {y, x};       else         b[++q] = {y, x};     }     sort(a + 1, a + p + 1);     sort(b + 1, b + q + 1);     for (int i = 1; i <= p; i++) aa[i] = a[i];     for (int i = 1; i <= q; i++) bb[i] = b[i];     for (int i = 1; i <= p; i++) a[i].second = max(a[i].second, a[i - 1].second);     for (int i = 1; i <= q; i++) b[i].second = max(b[i].second, b[i - 1].second);     int ans = 0;     for (int i = 2; i <= p; i++) {       int rm = c - a[i].first;       int id = upper_bound(a + 1, a + p + 1, make_pair(rm, inf)) - a;       id--;       if (id >= i) id = i - 1;       if (id > 0) ans = max(ans, aa[i].second + a[id].second);     }     for (int i = 2; i <= q; i++) {       int rm = d - b[i].first;       int id = upper_bound(b + 1, b + q + 1, make_pair(rm, inf)) - b;       id--;       if (id >= i) id = i - 1;       if (id > 0) ans = max(ans, bb[i].second + b[id].second);     }     int ad1 = -1, ad2 = -1;     for (int i = 1; i <= p; i++)       if (a[i].first <= c) ad1 = a[i].second;     for (int i = 1; i <= q; i++)       if (b[i].first <= d) ad2 = b[i].second;     if (ad1 != -1 && ad2 != -1) ans = max(ans, ad1 + ad2);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char mp[5500][5500];   int sum[5500][5500];   const int INF = 0x3f3f3f3f;   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %s , mp[i] + 1);     for (int i = 1; i <= n; ++i) {       int tot = 0;       for (int j = 1; j <= m; ++j) {         if (mp[i][j] ==  1 ) ++tot;         sum[i][j] = tot;       }     }     int mm = max(n, m), ans = INF;     for (int k = mm; k > 1; --k) {       bool fi = true;       int i, j, tj = k, ti = k, t0 = 0, t1 = 0, tans = 0;       for (i = 1; i <= ti; ++i) {         if (i > n || tj > m) {           if (i > n) fi = false;           if (i > n)             t0 += k;           else {             t1 += sum[i][m] - sum[i][tj - k];             t0 += k - (sum[i][m] - sum[i][tj - k]);           }         } else {           if (i == n) fi = false;           t1 += sum[i][tj] - sum[i][tj - k];           t0 += k - (sum[i][tj] - sum[i][tj - k]);         }         if (i == ti) {           tans += min(t0, t1);           t0 = 0, t1 = 0;         }         if (i == ti && tj < m) {           tj += k;           i = ti - k;         } else if (i == ti && fi && tj >= m) {           ti += k;           tj = k;         }       }       ans = min(ans, tans);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[5000];   vector<int> r[5000];   vector<int8_t> vis(5000);   int n, m, s;   void dfs(int src) {     vis[src] = true;     for (auto v : g[src]) {       if (!vis[v]) {         dfs(v);       }     }   }   int root(int src, vector<bool> &df) {     df[src] = true;     int c = 0;     for (int v : g[src]) {       if (!df[v] && !vis[v]) {         c += root(v, df) + 1;       }     }     return c;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> s;     --s;     for (int x, y, i = 0; i < m; ++i) {       cin >> x >> y;       g[--x].push_back(--y);       r[y].push_back(x);     }     dfs(s);     int ans = 0;     vector<pair<int, int>> sl;     for (int i = 0; i < n; ++i) {       if (!vis[i]) {         vector<bool> df(n);         int a = root(i, df);         sl.push_back({-a, i});       }     }     sort(sl.begin(), sl.end());     for (auto c : sl) {       if (!vis[c.second]) {         g[s].push_back(c.second);         dfs(s);         ++ans;       }     }     printf( %d n , ans);     return false & true;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const long long inf = 0x3f3f3f3f3f3f;   long long a[3][maxn], dp[3][maxn];   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int n;     cin >> n;     for (int j = (1); j < (3); j++)       for (int i = (1); i < (n + 1); i++) {         cin >> a[j][i];       }     a[0][0] = a[1][0] = a[2][0] = inf;     for (int i = (1); i < (n + 1); i++) {       dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]);       dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + a[1][i];       dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + a[2][i];     }     long long ans = 0;     for (int i = (0); i < (3); i++) ans = max(ans, dp[i][n]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int a[N], b[N], len;   bool vis[N];   int xx(int x) {     if (x & 1)       return x / 2;     else       return x / 2 - 1;   }   int main() {     int t;     cin >> t;     while (t--) {       len = 0;       memset(vis, 0, sizeof vis);       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];         if (a[i] >= 1 && a[i] <= n) {           if (!vis[a[i]])             vis[a[i]] = 1;           else             b[++len] = a[i];         } else {           b[++len] = a[i];         }       }       sort(b + 1, b + len + 1);       int j = len;       bool flag = 0;       for (int i = n; i > 0; i--) {         if (vis[i]) continue;         if (xx(b[j]) < i) {           flag = 1;           break;         } else {           j--;         }       }       if (flag)         cout << -1 << endl;       else         cout << len << endl;     }     return 0;   }