malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int N, K;   int arr[205];   int u[100005], v[100005], f[100005];   int lvl[205], ptr[205];   bool vis[205];   vector<int> graph[205];   vector<int> cgraph[205];   vector<vector<int>> vec;   void addedge(int a, int b, int k) {     u[K] = a;     v[K] = b;     u[K ^ 1] = b;     v[K ^ 1] = a;     f[K] = k;     graph[a].push_back(K);     graph[b].push_back(K ^ 1);     K += 2;   }   bool bfs() {     queue<int> qu;     qu.push(0);     fill(lvl, lvl + N + 2, 0);     lvl[0] = 1;     while (qu.size()) {       int n = qu.front();       qu.pop();       for (int e : graph[n]) {         if (f[e] && !lvl[v[e]]) {           lvl[v[e]] = lvl[u[e]] + 1;           qu.push(v[e]);         }       }     }     return lvl[N + 1];   }   int dfs(int n, int p) {     if (n == N + 1 || !p) {       return p;     }     for (int &i = ptr[n]; i < graph[n].size(); i++) {       int e = graph[n][i];       if (f[e] && lvl[v[e]] > lvl[n]) {         int k = dfs(v[e], min(f[e], p));         if (!k) {           continue;         }         f[e] -= k;         f[e ^ 1] += k;         return k;       }     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> arr[i];       if (arr[i] % 2 == 1) {         addedge(0, i, 2);       } else {         addedge(i, N + 1, 2);       }     }     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= N; j++) {         if (arr[i] % 2 == 1 && arr[j] % 2 == 0) {           bool isp = 1;           for (int k = 2; k <= sqrt(arr[i] + arr[j]); k++) {             if ((arr[i] + arr[j]) % k == 0) {               isp = 0;               break;             }           }           if (isp) {             addedge(i, j, 1);           }         }       }     }     int ans = 0;     while (1) {       if (!bfs()) {         break;       }       fill(ptr, ptr + 2 + N, 0);       int p;       while ((p = dfs(0, INT_MAX / 2))) {         ans += p;       }     }     if (ans != N) {       cout <<  Impossible n ;       return 0;     }     for (int e = 1; e < K; e += 2) {       if (f[e] && u[e] != 0 && v[e] != 0 && u[e] != N + 1 && v[e] != N + 1) {         cgraph[v[e]].push_back(u[e]);         cgraph[u[e]].push_back(v[e]);       }     }     for (int n = 1; n <= N; n++) {       if (!vis[n]) {         int c = n;         vector<int> temp;         while (!vis[c]) {           temp.push_back(c);           vis[c] = 1;           for (int e : cgraph[c]) {             if (!vis[e]) {               c = e;             }           }         }         vec.push_back(temp);       }     }     cout << vec.size() <<   n ;     for (auto k : vec) {       cout << k.size() <<    ;       for (int n : k) {         cout << n <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int main() {     scanf( %d%d , &n, &k);     if (k >= (n * (n - 1)) / 2)       puts( no solution );     else {       for (int i = 0, t = 1; t <= n; t++) printf( %d %d n , i, t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > a;   vector<int> color;   int n, m;   long long ans = 0;   void brut(int v) {     if (v == n) {       set<pair<int, int> > q;       vector<bool> find(n, false);       for (int i = 0; i < n; ++i) {         for (int j : a[i]) {           if (j < i) continue;           if (color[i] == -1 && color[j] == -1) continue;           if (color[i] == -1 || color[j] == -1) continue;           pair<int, int> temp = {color[i], color[j]};           if (temp.second < temp.first) swap(temp.first, temp.second);           if (q.find(temp) != q.end()) continue;           find[i] = find[j] = true;           q.insert(temp);           break;         }       }       for (int i = 0; i < n; ++i) {         for (int j : a[i]) {           if (j < i) continue;           if (color[i] == -1 && color[j] == -1) continue;           if (color[i] == -1 || color[j] == -1) continue;           pair<int, int> temp = {color[i], color[j]};           if (temp.second < temp.first) swap(temp.first, temp.second);           if (q.find(temp) != q.end()) continue;           find[i] = find[j] = true;           q.insert(temp);         }       }       for (int i = 0; i < n; ++i)         if (color[i] != -1 && !find[i]) return;       ans = max(ans, (long long)q.size());       return;     }     for (int i = -1; i < 6; ++i) {       color[v] = i;       brut(v + 1);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     a.resize(n);     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       a[x].push_back(y);       a[y].push_back(x);     }     color.resize(n);     brut(0);     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   long long n, x, y, z, ans;   long long a[N], b[N], par[N], sz[N];   long long get(long long x) {     if (par[x] == x) return x;     return par[x] = get(par[x]);   }   void merge(long long x, long long y) {     long long root_a = get(x);     long long root_b = get(y);     if (root_a == root_b) {       return;     }     if (sz[root_a] < sz[root_b]) {       par[root_a] = par[root_b];       sz[root_b] += sz[root_a];     } else {       par[root_b] = par[root_a];       sz[root_a] += sz[root_b];     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       long long n;       for (long long i = 0; i < N; i++) {         par[i] = i;         sz[i] = 1;       }       cin >> n;       for (long long i = 1; i < n + 1; i++) cin >> a[i];       for (long long i = 1; i < n + 1; i++) cin >> b[i];       for (long long i = 1; i < n + 1; i++) {         long long left = i - b[i];         long long right = i + b[i];         long long p1 = get(i);         if (left >= 1) {           long long p2 = get(left);           if (p1 != p2) merge(p1, p2);         }         if (right <= n) {           long long p2 = get(right);           if (p1 != p2) merge(p1, p2);         }       }       long long f = 0;       for (long long i = 1; i < n + 1; i++) {         long long p1 = get(i);         long long p2 = get(a[i]);         if (p1 != p2) f = 1;       }       if (f)         cout <<  NO n ;       else         cout <<  YES n ;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native )   using namespace std;   template <typename Tp>   inline void read(Tp &x) {     static char c;     static bool neg;     x = 0, c = getchar(), neg = false;     for (; !isdigit(c); c = getchar()) {       if (c ==  - ) {         neg = true;       }     }     for (; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     if (neg) {       x = -x;     }   }   const int N = 100000 + 5;   int n, w, q;   int a[N], b[N];   int mn[N], mx[N], ans[N];   inline void checkMax(int &x, const int &y) {     if (x < y) {       x = y;     }   }   inline void checkMin(int &x, const int &y) {     if (x > y) {       x = y;     }   }   int main() {     read(n), read(w), read(q);     for (int i = 0; i < n; ++i) {       read(a[i]);     }     for (int i = 0, x; i < q; ++i) {       read(x);       b[i] = w - x;     }     fill(mn, mn + q, a[0]);     fill(mx, mx + q, a[0]);     for (int j = 1; j < n; ++j) {       for (int i = 0; i < q; ++i) {         checkMax(mx[i], a[j]);         checkMin(mn[i], a[j]);         if (mx[i] - mn[i] > b[i]) {           ++ans[i];           mn[i] = mx[i] = a[j];         }       }     }     for (int i = 0; i < q; ++i) {       printf( %d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   inline void priv(vector<int> a) {     for (int i = 0; i < ((int)(a).size()); ++i)       printf( %d%c , a[i], i == (int)(a).size() - 1 ?   n  :    );   }   template <typename T>   istream& operator>>(istream& i, vector<T>& v) {     for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];     return i;   }   template <typename T>   string join(vector<T>& v) {     stringstream s;     for (int i = 0; i < ((int)(v).size()); ++i) s <<     << v[i];     return s.str().substr(1);   }   template <typename T>   ostream& operator<<(ostream& o, vector<T>& v) {     if ((int)(v).size()) o << join(v);     return o;   }   template <typename T1, typename T2>   istream& operator>>(istream& i, pair<T1, T2>& v) {     return i >> v.first >> v.second;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& o, pair<T1, T2>& v) {     return o << v.first <<  ,  << v.second;   }   const int MX = 100005, INF = 1001001001;   const long long int LINF = 1e18;   const double eps = 1e-10;   int main() {     int n;     scanf( %d , &n);     vector<int> x;     long long int sum = 0;     for (int i = 0; i < (n); ++i) {       int a, b, c, d;       scanf( %d%d%d%d , &a, &b, &c, &d);       if (a <= d && b <= c) continue;       long long int s = a + b, t = c + d;       if (s <= t) {         if (a <= d)           sum += c - b;         else           sum += a - d;       } else {         sum += a + c;         x.push_back(s);         x.push_back(t);       }     }     sort(x.begin(), x.end());     reverse(x.begin(), x.end());     for (int i = 0; i < ((int)(x).size()); ++i) {       if (i & 1) sum -= x[i];     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long q;     cin >> q;     while (q--) {       long long n, count = 0;       cin >> n;       long long a[100005];       for (int i = 0; i < n; i++) cin >> a[i];       if (n == 1)         cout <<  1  << endl;       else {         for (int i = 0; i < n; i++) {           for (int j = i + 1; j < n; j++) {             if ((a[i] - a[j]) == 1 || (a[i] - a[j] == -1)) count++;           }         }         if (count > 0)           cout <<  2  << endl;         else           cout <<  1  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, i, j, k, s, a[50], b[50], c[50];   long long x;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %I64d , &x);       for (j = 0; (1ll << j) < x; j++)         ;       if ((1ll << j) == x)         a[j]++;       else         b[j - 1]++;     }     for (i = a[0]; i > 0; i--) {       k = i;       s = 0;       for (j = 0; j <= 40; j++) {         k = min(k, a[j]);         c[j] = k;       }       for (j = 40; j >= 0; j--) {         s += b[j] + a[j] - c[j];         if (s > c[j]) break;       }       if (j >= 0) break;     }     if (i == a[0])       cout <<  -1 ;     else       for (i++; i <= a[0]; i++) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;      #define ll long long int   #define pll pair<ll, ll>   #define vl vector<ll>   #define pb push_back   #define pp pop_back   #define f(i, a, b) for (ll i = a; i < b; ++i)   #define rev(i, a, b) for (ll i = a; i >= b; --i)   #define print(x) cout << x << endl   #define endl   n    #define F first   #define S second   #define setbits(x) __builtin_popcountll(x)   #define zerobits(x) __builtin_ctzll(x)   #define to(n) to_string(n)   #define low(v, n) lower_bound(v.begin(), v.end(), n) - v.begin()   #define upp(v, n) upper_bound(v.begin(), v.end(), n) - v.begin()   #define mod 998244353   #define mex 100005      ll power(ll x, ll y)   {       if (y == 0)       {           return 1;       }       if (y % 2 == 0)       {           return power((x % mod) * (x % mod), y / 2) % mod;       }       else       {           return ((x % mod) * power((x % mod) * (x % mod), y / 2) % mod);       }   }      ll modinverse(ll a, ll m)   {       return power(a, m - 2);   }      ll ncr(ll n, ll r)   {       ll k = min(r, n - r);       ll result = 1;       ll divide = 1;          f(i, 1, k + 1)       {           result = ((result % mod) * ((n + 1 - i) % mod)) % mod;           divide = ((divide % mod) * (i % mod)) % mod;       }          result = (result * modinverse(divide, mod)) % mod;       return result;   }      int main()   {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);          ll t;       cin >> t;       while (t--)       {           ll n;           cin >> n;           string s;           cin >> s;              ll p = 0;           ll q = 0;           ll i = 0;           while (i < n)           {               if (s[i] ==  0 )               {                   p++;                   ++i;               }               else if (s[i] ==  1  && i + 1 < n && s[i + 1] ==  1 )               {                   q++;                   i += 2;               }               else               {                   ++i;               }           }              print(ncr(p + q, p));       }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v;   int N, M;   long long f(int a, int b) {     long long res = 1;     for (int i = 1; i <= a; i++) {       int ii = i;       while (b > 0 && ii % 2 == 0) {         ii /= 2;         b--;       }       res = (res * ii) % M;     }     return res;   }   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       int x;       scanf( %d , &x);       v.push_back(make_pair(x, i + 1));     }     for (int i = 0; i < N; i++) {       int x;       scanf( %d , &x);       v.push_back(make_pair(x, i + 1));     }     scanf( %d , &M);     sort(v.begin(), v.end());     long long res = 1;     int cnt = 0;     int b = 0;     for (int i = 0; i < N * 2; i++) {       if (i > 0 && v[i].first != v[i - 1].first) {         res = (res * f(cnt, b)) % M;         cnt = 1;         b = 0;       } else {         if (i != 0 && v[i] == v[i - 1]) b++;         cnt++;       }     }     res = (res * f(cnt, b)) % M;     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b;     scanf( %d  %d , &a, &b);     int diff, same, total;     total = a + b;     if (a > b) {       diff = b;     } else {       diff = a;     }     same = (total - (2 * diff)) / 2;     printf( %d  %d n , diff, same);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 40005;   const int M = 1005;   const int Q = 1000000007;   const int P = 10000019;   int n, m, q, tot;   int v[N], w[N], Ask[N], f[N], id[N];   int g[M], dp[N * 4];   vector<int> T[N * 4];   void Build(int s, int x, int y, int l, int r, int k) {     if (l <= x && y <= r) {       T[s].push_back(k);       return;     }     int Mid = (x + y) / 2;     int t = s + s;     if (l <= Mid) Build(t, x, Mid, l, r, k);     if (Mid < r) Build(t + 1, Mid + 1, y, l, r, k);   }   void Make(int s, int x, int y) {     if (x == y) {       dp[s] = Ask[x];       return;     }     int Mid = (x + y) / 2;     int t = s + s;     Make(t, x, Mid);     Make(t + 1, Mid + 1, y);     dp[s] = dp[t] | dp[t + 1];   }   void Add(int dp[M], int y, int x) {     for (int i = m; i >= x; i--) dp[i] = max(dp[i], dp[i - x] + y);   }   void print() {     int Ans = 0;     for (int i = m; i; i--) Ans = (1LL * P * Ans + g[i]) % Q;     printf( %d n , Ans);   }   void Work(int s, int x, int y) {     if (!dp[s]) return;     int Mid = (x + y) / 2;     int tmp[N];     for (int i = 0; i <= m; i++) tmp[i] = g[i];     for (int j = 0; j < T[s].size(); j++) Add(g, v[T[s][j]], w[T[s][j]]);     if (x == y) {       print();       for (int i = 0; i <= m; i++) g[i] = tmp[i];       return;     }     int t = s + s;     Work(t, x, Mid);     Work(t + 1, Mid + 1, y);     for (int i = 0; i <= m; i++) g[i] = tmp[i];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &v[i], &w[i]);       f[i] = 1;       id[i] = i;     }     scanf( %d , &q);     tot = n;     for (int i = 1; i <= q; i++) {       int x;       scanf( %d , &x);       if (x == 1) {         tot++;         scanf( %d%d , &v[tot], &w[tot]);         f[tot] = 1;         id[tot] = n + i;       } else if (x == 2) {         int y;         scanf( %d , &y);         Build(1, 1, n + q, id[y], n + i, y);         f[y] = 0;       } else if (x == 3) {         Ask[n + i] = 1;       }     }     for (int i = 1; i <= n; i++)       if (f[i]) Add(g, v[i], w[i]);     for (int i = n + 1; i <= tot; i++)       if (f[i]) Build(1, 1, n + q, id[i], n + q, i);     Make(1, 1, n + q);     Work(1, 1, n + q);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     using T = tuple<long long, long long, long long, long long>;     vector<long long> x(n), y(n), z(n);     for (long long i = (0); i < ((n)); ++i) cin >> x[i] >> y[i] >> z[i];     vector<long long> flag(n, 0);     vector<pair<long long, long long> > ans;     for (long long i = (0); i < ((n)); ++i) {       if (flag[i]) continue;       flag[i]++;       bool check = true;       long long X = (1LL << 60), Y, Z, id;       for (long long j = (0); j < ((n)); ++j) {         if (flag[j]) continue;         if (X == (1LL << 60)) {           X = x[j], Y = y[j], Z = z[j];           id = j;           continue;         }         if (((min(x[i], X)) <= (x[j]) && (x[j]) < (max(x[i], X) + 1)) &&             ((min(y[i], Y)) <= (y[j]) && (y[j]) < (max(y[i], Y) + 1)) &&             ((min(z[i], Z)) <= (z[j]) && (z[j]) < (max(z[i], Z) + 1))) {           X = x[j], Y = y[j], Z = z[j];           id = j;           continue;         }       }       flag[id]++;       ans.push_back(pair<long long, long long>(i + 1, id + 1));     }     for (long long i = (0); i < ((n / 2)); ++i)       cout << ans[i].first <<     << ans[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {       int n, m;       cin >> n >> m;       int cnt = 0;       set <int> s;       while(n) {           s.insert(n % m);           cnt++;           n /= m;       }       if(s.size() == cnt) cout <<  YES n ;       else cout <<  NO n ;       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1E9 + 7;   template <class C>   void mini(C& a4, C b4) {     a4 = min(a4, b4);   }   template <class C>   void maxi(C& a4, C b4) {     a4 = max(a4, b4);   }   int n, k;   int il[2];   const long long mod = 1E9 + 7;   int best[2][55][55];   int ile[2][55][55];   int a, b;   int binom[55][55];   int main() {     ios_base::sync_with_stdio(false);     binom[0][0] = 1;     for (int i = (1); i <= (55 - 1); ++i) {       binom[i][0] = 1;       for (int j = (1); j <= (55 - 1); ++j) {         binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % mod;       }     }     cin >> n >> k;     for (int i = (1); i <= (n); ++i) {       int x;       cin >> x;       if (x == 50)         il[0]++;       else         il[1]++;     }     for (int s = (0); s <= (1); ++s)       for (int i = (0); i <= (55 - 1); ++i)         for (int j = (0); j <= (55 - 1); ++j) best[s][i][j] = INF;     a = il[0];     b = il[1];     best[0][a][b] = 0;     ile[0][a][b] = 1;     for (int moves = (0); moves <= (55 * 55 * 10); ++moves) {       for (int s = (0); s <= (1); ++s)         for (int i = (0); i <= (a); ++i)           for (int j = (0); j <= (b); ++j) {             if (best[s][i][j] == moves) {               for (int ii = (0); ii <= (i); ++ii)                 for (int jj = (0); jj <= (j); ++jj)                   if (ii || jj) {                     if (ii * 50 + jj * 100 > k) break;                     int x = a - i;                     int y = b - j;                     x += ii;                     y += jj;                     long long il = (binom[i][ii] * (long long)binom[j][jj]) % mod;                     if (moves + 1 < best[1 - s][x][y]) {                       best[1 - s][x][y] = moves + 1;                       ile[1 - s][x][y] = (ile[s][i][j] * il) % mod;                     } else if (moves + 1 == best[1 - s][x][y]) {                       ile[1 - s][x][y] += (ile[s][i][j] * il) % mod;                       ile[1 - s][x][y] %= (int)mod;                     }                   }             }           }     }     if (best[1][a][b] == INF) best[1][a][b] = -1;     cout << best[1][a][b] << endl << ile[1][a][b] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1007;   int c[N], t[N];   bool cmp(int i, int j) { return c[i] > c[j]; }   int main() {     int n, k;     cin >> n >> k;     vector<int> v[3];     for (int i = 0; i < n; ++i) {       cin >> c[i] >> t[i];       v[t[i]].push_back(i);     }     sort((v[1]).begin(), (v[1]).end(), cmp);     int sz = (int)((v[1]).size()), uu = (int)((v[2]).size());     double sum = 0;     if (sz < k) {       for (int i = 0; i < sz; ++i) sum += (double)c[v[1][i]] / 2;       for (int i = 0; i < uu; ++i) sum += c[v[2][i]];       cout << fixed << setprecision(1) << sum <<   n ;       for (int i = 0; i < sz; ++i) cout << 1 <<     << v[1][i] + 1 <<   n ;       for (int i = 0; i < k - sz - 1; ++i)         cout << 1 <<     << v[2][i] + 1 <<   n ;       cout << (n - (k - 1)) <<    ;       for (int i = k - sz - 1; i < n - sz; ++i) cout << v[2][i] + 1 <<    ;       cout <<   n ;     } else {       for (int i = 0; i < k - 1; ++i) sum += (double)c[v[1][i]] / 2;       int mini = 1000000000;       for (int i = k - 1; i < sz; ++i) {         sum += c[v[1][i]];         mini = min(mini, c[v[1][i]]);       }       for (int i = 0; i < uu; ++i) {         sum += c[v[2][i]];         mini = min(mini, c[v[2][i]]);       }       sum -= (double)mini / 2;       cout << fixed << setprecision(1) << sum <<   n ;       for (int i = 0; i < k - 1; ++i) cout << 1 <<     << v[1][i] + 1 <<   n ;       cout << (n - (k - 1)) <<    ;       for (int i = k - 1; i < sz; ++i) cout << v[1][i] + 1 <<    ;       for (int i = 0; i < uu; ++i) cout << v[2][i] + 1 <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool is_vowel(const char c) {     for (const char vowel : { a ,  e ,  i ,  o ,  u })       if (c == vowel) return true;     return false;   }   bool is_block_ok(const array<char, 3> cs) {     for (const char c : cs)       if (is_vowel(c)) return true;     return cs[0] == cs[1] && cs[1] == cs[2];   }   int main() {     string s;     cin >> s;     const int n = int(s.length());     int start = 0;     for (int i = 0; i < n; i++) {       if (i >= start + 2 && !is_block_ok({s[i - 2], s[i - 1], s[i]})) {         cout <<    ;         start = i;       }       cout << s[i];     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     long long int k;     cin >> n >> k;     vector<pair<int, int> > a(n);     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;     }     sort(a.begin(), a.end());     int ans = -1;     long long int l = 0, r = 2e9;     for (int i = 0; i < 60; i++) {       long long int m = l + (r - l) / 2;       int less = 0, right = 0, center = 0;       long long int money = 0;       vector<int> c;       for (auto &e : a) {         if (e.second < m) {           money += e.first;         } else if (e.first >= m) {           money += e.first;           right++;         } else if (e.first < m && m <= e.second) {           c.push_back(e.first);         }       }       int need = max(0, (n + 1) / 2 - right);       if (need > c.size()) {         r = m - 1;       } else {         for (int i = 0; i < c.size(); i++) {           if (i < c.size() - need)             money += c[i];           else             money += m;         }         if (money <= k) {           ans = m;           l = m + 1;         } else {           r = m - 1;         }       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }