malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795;   long long int inp() {     long long int n = 0, s = 1;     char c;     for (c = getchar(); c < 48 || c > 58; c = getchar())       if (c ==  - ) s = -1;     for (; c > 47 && c < 59; c = getchar()) n = n * 10 + c - 48;     return n * s;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       gcd(b, a % b);   }   long long int square(long long int n) { return n * n; }   long long int bigmod(long long int b, long long int p, long long int m) {     if (p == 0)       return 1;     else if (p % 2 == 0)       return square(bigmod(b, p / 2, m)) % m;     else       return ((b % m) * bigmod(b, p - 1, m)) % m;   }   long long mulmod(long long a, long long b, long long c) {     long long x = 0, y = a % c;     while (b > 0) {       if (b % 2 == 1) {         x = (x + y) % c;       }       y = (y * 2) % c;       b /= 2;     }     return x % c;   }   long long int vis[55][55], n, m;   char ch[55][55];   long long int fun(long long int i, long long int j, char z, char d) {     long long int p = 0;     vis[i][j] = 1;     if ((j + 1) < m && vis[i][j + 1] == 0 && ch[i][j + 1] == z && d !=  l ) {       p = fun(i, j + 1, z,  r );     } else if ((j + 1) < m && vis[i][j + 1] == 1 && ch[i][j + 1] == z &&                d !=  l ) {       return 1;     }     if ((i + 1) < n && vis[i + 1][j] == 0 && ch[i + 1][j] == z && d !=  u ) {       p = fun(i + 1, j, z,  d );     } else if ((i + 1) < n && vis[i + 1][j] == 1 && ch[i + 1][j] == z &&                d !=  u ) {       return 1;     }     if ((j - 1) >= 0 && vis[i][j - 1] == 0 && ch[i][j - 1] == z && d !=  r ) {       p = fun(i, j - 1, z,  l );     } else if ((j - 1) >= 0 && vis[i][j - 1] == 1 && ch[i][j - 1] == z &&                d !=  r ) {       return 1;     }     if ((i - 1) >= 0 && vis[i - 1][j] == 0 && ch[i - 1][j] == z && d !=  d ) {       p = fun(i - 1, j, z,  u );     } else if ((i - 1) >= 0 && vis[i - 1][j] == 1 && ch[i - 1][j] == z &&                d !=  d ) {       return 1;     }     return p;   }   int main() {     long long int t, ans = 0, i, j, k;     cin >> n >> m;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) cin >> ch[i][j];     }     long long int f = 0;     for (k = 0; k < 25; k++) {       f = 0;       for (i = 0; i < n; i++) {         f = 0;         for (j = 0; j < m; j++) {           if (ch[i][j] == (char)( A  + k) && vis[i][j] != 1 &&               fun(i, j, (char)( A  + k),  a )) {             cout <<  Yes n ;             f = 1;             break;           }         }         if (f == 1) break;       }       if (f == 1) {         break;       }     }     if (f == 0) cout <<  No n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000100;   const int M = 20;   vector<int> g[N];   vector<int> gr[N];   vector<int> ord;   int sp[N][M];   int tin[N];   int tout[N];   int timer;   void pre_dfs(int v, int p = -1) {     sp[v][0] = (p == -1 ? v : p);     for (int i = 1; i < M; i++) {       sp[v][i] = sp[sp[v][i - 1]][i - 1];     }     tin[v] = timer++;     for (int to : g[v]) {       pre_dfs(to, v);     }     tout[v] = timer++;   }   inline bool anc(int u, int v) {     return (tin[u] <= tin[v] && tout[u] >= tout[v]);   }   int get_par(int v, int k) {     for (int i = 0; i < M; i++) {       if ((k >> i) & 1) {         v = sp[v][i];       }     }     return v;   }   bool mark[N];   void dfs1(int v) {     mark[v] = 1;     for (int to : g[v]) {       if (!mark[to]) {         dfs1(to);       }     }     ord.push_back(v);   }   bool good[N];   int comp[N];   int val[N];   int cur;   void dfs2(int v) {     comp[v] = cur;     val[cur] += good[v];     for (int to : gr[v]) {       if (comp[to] == -1) {         dfs2(to);       }     }   }   int dp[N];   int dfs_end(int v) {     if (dp[v] != -1) return dp[v];     dp[v] = val[v];     for (int to : g[v]) {       dp[v] = max(dp[v], dfs_end(to) + val[v]);     }     return dp[v];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<pair<int, int>> ed;     for (int i = 1; i < n; i++) {       int p;       cin >> p;       --p;       g[p].push_back(i);       gr[i].push_back(p);       ed.emplace_back(p, i);     }     pre_dfs(0);     for (int i = 0; i < n; i++) {       good[i] = g[i].empty();       if (!good[i]) continue;       int up = get_par(i, k);       g[i].push_back(up);       gr[up].push_back(i);     }     for (int i = 0; i < n; i++) {       if (!mark[i]) {         dfs1(i);       }     }     memset(comp, -1, sizeof(comp));     for (int i = n - 1; i >= 0; i--) {       int v = ord[i];       if (comp[v] == -1) {         dfs2(v);         ++cur;       }     }     for (int i = 0; i < n; i++) {       g[i].clear();       gr[i].clear();     }     for (auto u : ed) {       int x = comp[u.first];       int y = comp[u.second];       if (x != y) {         g[x].push_back(y);       }     }     memset(dp, -1, sizeof(dp));     cout << dfs_end(comp[0]) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, s, i, l = 0, k = 0, j = 0, t = 0, p = 0, max = 0;     cin >> n;     int a[n];     for (i = 0; i < n; i++) {       k++;       cin >> a[i];       if (a[i] == 1) {         l++;       }       if (a[i] == 2) {         j++;       }       if (a[i] == 3) {         t++;       }       if (l > j) {         max = l;       }       if (j > max) {         max = j;       } else if (t > max) {         max = t;       }     }     cout << (n - max) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, n;   long long mod = 1000000007;   vector<long long> factorial(1000005);   bool excellent(long long z) {     while (z != 0) {       if (z % 10 != a && z % 10 != b) return false;       z /= 10;     }     return true;   }   long long pow(long long a, long long p) {     if (p == 0) return 1;     if (p % 2 == 1) return (a * pow(a, p - 1)) % mod;     long long v = pow(a, p >> 1);     return (v * v) % mod;   }   int calc(int n, int m) {     return (factorial[n] * (pow(factorial[m], mod - 2) % mod) % mod *             (pow(factorial[n - m], mod - 2) % mod) % mod);   }   int main() {     cin >> a >> b >> n;     factorial[1] = 1;     for (int i = 2; i <= n; i++) factorial[i] = (factorial[i - 1] * i) % mod;     long long count = 0;     for (int i = 0; i <= n; i++) {       if (excellent(a * i + b * (n - i))) {         if (n - i != 0 && i != 0) {           count += calc(n, i);           count = count % mod;         } else           count++;       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   struct line {     int a, b;     line() {}     line(int a, int b) : a(a), b(b) {}     bool operator<(const line& o) const { return a < o.a; }     friend line operator+(const line& first, const line& second) {       if (second < first) return second + first;       if (first.b >= second.a && first.b < second.b)         return line(first.a, second.b);       return first;     }     void print() { printf( (%d, %d)  , a, b); }   };   struct node {     vector<line> box;     node() {}     node(line first) { box = {first}; }     int size() { return (int)(box).size(); }     friend node operator+(const node& X, const node& Y) {       const vector<line>& first = X.box;       const vector<line>& second = Y.box;       int l = 0, r = 0;       node T;       vector<line>& t = T.box;       while (l < first.size() && r < second.size()) {         if (first[l] < second[r])           t.push_back(first[l++]);         else           t.push_back(second[r++]);       }       while (l < first.size()) t.push_back(first[l++]);       while (r < second.size()) t.push_back(second[r++]);       vector<line> Stack;       Stack.push_back(t.back());       for (int i = ((int)(t).size() - 2); i >= (0); --i) {         line& c = t[i];         while (!Stack.empty() && Stack.back().a <= c.b) {           c.b = max(c.b, Stack.back().b);           Stack.pop_back();         }         Stack.push_back(c);       }       Stack.clear();       return T;     }     line search(int a) {       int l = 0, r = size();       while (l < r) {         int m = (l + r) >> 1;         if (box[m].a < a)           l = m + 1;         else           r = m;       }       if (l != size()) return box[l];       return line(inf, inf);     }     void print() {       printf( {  );       for (line& e : box) {         e.print();         cout <<    ;       }       printf( } n );     }   };   const int N = 100005;   line rope[N];   node seg[N << 2];   void build(int l, int r, int now) {     if (l == r) {       seg[now] = node(rope[l]);       return;     }     int m = (l + r) >> 1;     int L = (now << 1), R = (now << 1 | 1);     build(l, m, L);     build(m + 1, r, R);     seg[now] = seg[L] + seg[R];   }   line get(int ll, int rr, int l, int r, int now) {     if (ll <= l && r <= rr) {       return seg[now].search(ll);     }     if (rr < l || r < ll) return line(inf, inf);     int m = (l + r) >> 1;     return get(ll, rr, l, m, now << 1) + get(ll, rr, m + 1, r, now << 1 | 1);   }   void solve() {     int n, m;     cin >> n >> m;     for (int i = (1); i <= (m); ++i) {       int a, b;       cin >> a >> b;       rope[b] = {a, b};     }     build(1, n, 1);     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       line ans = get(a, b, 1, n, 1);       if (ans.a != a)         printf( %d n , a);       else         printf( %d n , ans.b);     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int N = 4000090, M = 1000000007;   int t[N];   void add(int x, int l, int r, int p, int v) {     if (p > r or p < l) return;     if (l == r) {       t[x] += v;       return;     }     int m = (l + r) / 2;     add(2 * x, l, m, p, v);     add(2 * x + 1, m + 1, r, p, v);     t[x] = t[2 * x] + t[2 * x + 1];     return;   }   int kth(int x, int l, int r, int k) {     if (l == r) return l;     int m = (l + r) / 2;     if (t[2 * x] >= k)       return kth(2 * x, l, m, k);     else       return kth(2 * x + 1, m + 1, r, k - t[2 * x]);   }   int main() {     int n, q, x;     scanf( %d %d , &n, &q);     for (int i = 0; i < n; ++i) scanf( %d , &x), add(1, 1, n, x, 1);     for (int Q = 0; Q < q; ++Q) {       scanf( %d , &x);       if (x > 0)         add(1, 1, n, x, 1);       else         add(1, 1, n, kth(1, 1, n, -x), -1);     }     if (!t[1])       puts( 0 );     else       printf( %d , kth(1, 1, n, 1));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     int n = s.size();     char c;     vector<pair<char, char>> a;     for (int i = 0; i < n; i++)       if (s[i] != t[i]) {         c = t[i];         for (int j = 0; j < n; j++)           if (t[j] == c && s[j] == s[i] || t[j] == s[i] && s[j] == c) {             if (t[j] == c)               t[j] = s[i];             else               t[j] = c;           } else if (t[j] == c || s[j] == s[i] || t[j] == s[i] || s[j] == c) {             cout << -1;             return 0;           }         a.push_back(make_pair(c, s[i]));       }     cout << a.size() << endl;     for (int i = 0; i < a.size(); i++)       cout << a[i].first <<     << a[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double ans = 1;   int p, d, h;   int main() {     cin >> p >> d >> h;     int top = 0;     int kh;     for (int i = 1; i <= d; i++) {       int x;       cin >> x;       top += x;       if (i == h) {         kh = x;       }     }     if (top < p) {       cout << -1;       return 0;     } else {       double t = 1;       int temp = top - 1;       for (int i = p - 1; i > 0; i--) {         t *= ((double)temp / (double)i);         temp--;       }       double ist = 1;       int temp2 = top - kh;       for (int i = p - 1; i > 0; i--) {         ist *= ((double)temp2 / (double)i);         temp2--;       }       double aist = t - ist;       ans = aist / t;       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   clock_t clk = clock();   int i, j;   void solve(void);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t = 1;     while (t--) solve();     return 0;   }   int n, m, a, b;   bool cnt;   bool vis[1501][1501];   char maze[1501][1501];   set<pair<int, int> > s[1501][1501];   int dfs(int x, int y, int ex, int ey, int cntx, int cnty) {     auto it = s[x][y].find({cntx, cnty});     if (vis[x][y] == 1 && it != s[x][y].end())       return 0;     else if (vis[x][y] == 1)       return -1;     vis[x][y] = 1;     s[x][y].insert({cntx, cnty});     int val = 0, valx = cntx, valy = cnty;     if (maze[x][((y - 1) % m + m) % m] !=  #  && ((y - 1) % m + m) % m != ey) {       valx = cntx, valy = cnty;       if (y - 1 == -1) --valy;       val = dfs(x, ((y - 1) % m + m) % m, x, y, valx, valy);     }     if (val == -1) return val;     if (maze[x][((y + 1) % m + m) % m] !=  #  && ((y + 1) % m + m) % m != ey) {       valx = cntx, valy = cnty;       if (y + 1 == m) ++valy;       val = dfs(x, ((y + 1) % m + m) % m, x, y, valx, valy);     }     if (val == -1) return val;     if (maze[((x - 1) % n + n) % n][y] !=  #  && ((x - 1) % n + n) % n != ex) {       valx = cntx, valy = cnty;       if (x - 1 == -1) --valx;       val = dfs(((x - 1) % n + n) % n, y, x, y, valx, valy);     }     if (val == -1) return val;     if (maze[((x + 1) % n + n) % n][y] !=  #  && ((x + 1) % n + n) % n != ex) {       valx = cntx, valy = cnty;       if (x + 1 == n) ++valx;       val = dfs(((x + 1) % n + n) % n, y, x, y, valx, valy);     }     if (val == -1) return val;     return 0;   }   void solve() {     cin >> n >> m;     for (i = 0; i <= n - 1; ++i)       for (j = 0; j <= m - 1; ++j) {         cin >> maze[i][j];         if (maze[i][j] ==  S ) a = i, b = j;       }     int val = dfs(a, b, -1, -1, 0, 0);     if (val == -1)       cout <<  Yes ;     else       cout <<  No ;     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<int> arr(n);     for (auto& x : arr) cin >> x;     vector<int> p(m);     for (int i = 0; i < m; i++) p[i] = i;     vector<vector<int>> mp(m);     int ans = 0;     for (int i = 0; i < n; i++) {       if (i > 0 && arr[i - 1] != arr[i]) ans++;       mp[arr[i] - 1].push_back(i);     }     cout << ans << endl;     for (int i = 0; i < m - 1; i++) {       int u, v;       cin >> u >> v;       u--, v--;       while (p[u] != u) {         u = p[u];       }       while (p[v] != v) {         v = p[v];       }       if (mp[v].size() > mp[u].size()) swap(u, v);       for (int x : mp[v]) {         if (x + 1 < n && arr[x + 1] == u + 1) ans--;         if (x > 0 && arr[x - 1] == u + 1) ans--;       }       for (int x : mp[v]) {         arr[x] = u + 1;         mp[u].push_back(x);       }       mp[v].clear();       p[v] = u;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, x, v[10001], w[10001], f[10001], g[10001], ans = -1;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       w[i] = v[i] - x * k;     }     for (int i = 1; i <= 10000; i++) f[i] = g[i] = -1 << 30;     for (int i = 0; i <= n; i++) {       if (w[i] >= 0)         for (int j = 10000; j >= w[i]; j--) f[j] = max(f[j - w[i]] + v[i], f[j]);     }     for (int i = 0; i <= n; i++) {       if (w[i] < 0)         for (int j = 10000; j >= -w[i]; j--) g[j] = max(g[j + w[i]] + v[i], g[j]);     }     for (int i = 0; i <= 10000; i++)       if (f[i] || g[i]) ans = max(ans, f[i] + g[i]);     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a;     cin >> a;     map<string, long long> arr;     for (long long i = 0; i < a; i++) {       string s1;       cin >> s1;       arr[s1] = -i;       arr.insert(pair<string, long long>(s1, -i));     }     vector<pair<long long, string>> ar1;     for (auto it = arr.begin(); it != arr.end(); it++) {       ar1.push_back(make_pair(it->second, it->first));     }     sort(ar1.begin(), ar1.end());     for (auto it = ar1.begin(); it != ar1.end(); it++) {       cout << it->second << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   bool check[100];   int main() {     int n;     string s;     cin >> n;     cin >> s;     int ans = 0;     for (int x = 0; x < s.size(); ++x) {       if (!check[s[x] -  a ]) {         ans++;         check[s[x] -  a ] = 1;       }     }     cout << ((ans >= n) ?  YES  :  NO ) << endl;     if (ans >= n) {       for (int x = 0; x < s.size(); ++x) {         if (n) {           if (check[s[x] -  a ]) {             if (x) cout << endl;             cout << s[x];             check[s[x] -  a ] = 0;             n--;           } else {             cout << s[x];           }         } else           cout << s[x];       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, x, y, c;     cin >> n >> x >> y;     int a[n];     for (i = 0; i < n; i++) cin >> a[i];     if (x > y)       cout << n << endl;     else {       c = 0;       for (i = 0; i < n; i++)         if (a[i] <= x) c++;       if (c % 2 == 1)         c = c / 2 + 1;       else         c /= 2;       cout << c << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 5;   const int K = 30;   int p[N];   char s[N];   int get(int l, int r, int s) {     l = max(l, s * K);     if (l > r) return 0;     return r / s - l / s;   }   int main() {     scanf( %s , s);     int n = strlen(s);     for (int i = 0; i < n; ++i) p[i + 1] = p[i] + (int)(s[i] ==  1 );     long long ans = 0;     map<int, int> cnt;     for (int k = 1; k <= K; ++k) {       cnt.clear();       for (int i = 0; i <= n; ++i) ++cnt[i - k * p[i]];       for (auto pr : cnt) ans += pr.second * (long long)(pr.second - 1) / 2;     }     vector<int> one;     for (int i = 0; i < n; ++i)       if (s[i] ==  1 ) one.push_back(i);     one.push_back(n);     reverse((one).begin(), (one).end());     for (int i = 0; i < n; ++i) {       int sz = (int)(one).size();       for (int j = 0; j < min(n / K + 1, sz - 1); ++j)         ans += get(one[sz - j - 1] - i, one[sz - (j + 1) - 1] - i, j + 1);       if (s[i] ==  1 ) one.pop_back();     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, k, link;     cin >> n >> k;     vector<int> ans(n + 1);     for (int i = 1; i <= n; i++) {       cin >> link;       ans[i] = min(n, i + k) - max(1, i - k) + 1;       if (link != 0) {         ans[i] += ans[link] - max(0, (min(n, link + k) - max(1, i - k) + 1));       }       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long int n, x = 1, ans = 0, w = 0, q;       string s;       cin >> n;       long long int p = pow(2, 32) - 1;       stack<long long int> stackstack;       for (int i = 0; i < n; i++) {         cin >> s;         if (s ==  for ) cin >> q;         if (s ==  add  && stackstack.empty() == 1) {           if (ans + 1 > p) {             cout <<  OVERFLOW!!! ;             return 0;           } else             ans += 1;         } else if (s ==  add ) {           if (stackstack.top() == p + 1) {             cout <<  OVERFLOW!!! ;             return 0;           }           if (stackstack.top() + ans > p) {             cout <<  OVERFLOW!!! ;             return 0;           }           ans += stackstack.top();         } else if (s ==  end ) {           stackstack.pop();         } else if (s ==  for ) {           if (stackstack.empty())             x = 1;           else             x = stackstack.top();           if (x * q > p)             stackstack.push(p + 1);           else             stackstack.push(x * q);         }       }       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct pawn {     long long int r;     long long int c;   };   struct pawn b[100], w[100];   int main() {     ios::sync_with_stdio(false);     char a;     long long int l = 0, h = 0;     for (int i = 1; i <= 8; i++) {       for (int j = 1; j <= 8; j++) {         cin >> a;         if (a ==  B ) {           b[l].r = i;           b[l].c = j;           l++;         } else if (a ==  W ) {           w[h].r = i;           w[h].c = j;           h++;         }       }     }     long long int w_r, w_c;     for (int i = 0; i < h; i++) {       int f = 0;       for (int j = 0; j < l; j++) {         if (b[j].r < w[i].r && b[j].c == w[i].c) {           f = 1;           break;         }       }       if (f == 0) {         w_r = w[i].r;         w_c = w[i].c;         break;       }     }     long long int b_r, b_c;     for (int i = l - 1; i >= 0; i--) {       int f = 0;       for (int j = h - 1; j >= 0; j--) {         if (w[j].r > b[i].r && w[j].c == b[i].c) {           f = 1;           break;         }       }       if (f == 0) {         b_r = b[i].r;         b_c = b[i].c;         break;       }     }     long long int diff_w = w_r - 1;     long long int diff_b = 8 - b_r;     if (diff_w == diff_b)       cout <<  A  << endl;     else if (diff_w < diff_b)       cout <<  A  << endl;     else       cout <<  B  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void MAIN() {     long long N;     cin >> N;     string S = to_string(N);     reverse(S.begin(), S.end());     int sz = (int)S.size();     long long ans = -2;     for (int i = 0; i < (1 << sz); i++) {       int i_c = i;       if ((i_c >> (sz - 1) & 1) || (i_c >> (sz - 2) & 1)) {         continue;       }       string T = S;       long long now = 1;       for (int j = 0; j < sz; j++) {         if (i_c >> j & 1) {           int X = 10 + (int)(T[j] -  0 );           now *= 19 - X;           if (T[j + 2] ==  0 ) {             if (i_c >> (j + 2) & 1) {               T[j + 2] =  9 ;               i_c ^= (1 << (j + 2));             } else {               now = 0;               break;             }           } else {             T[j + 2]--;           }         } else {           now *= (int)(T[j] -  0 ) + 1;           if (T[j] ==  9  && j >= 2 && (i >> (j - 2) & 1)) {             T[j + 2]--;           }         }       }       ans += now;     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       MAIN();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long ispossible(vector<long long>& b, vector<long long>& p, int k,                               long long a) {     int n = b.size();     if (k > p.size()) return -1;     long long c = 0, s = 0, extra = 0;     for (int i = n - k; i < n; i++) {       c += p[i - n + k];       extra += max(p[i - n + k] - b[i], 0ll);     }     if (extra > a) return -1;     long long e = c - a;     return e > 0 ? e : 0;   }   int main() {     int n, m;     long long a;     cin >> n >> m >> a;     vector<long long> b(n, 0), p(m, 0);     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < m; i++) cin >> p[i];     sort(b.begin(), b.end());     sort(p.begin(), p.end());     int l, r;     long long tcost, cost = 0;     l = 0, r = n;     while (l < r) {       m = (l + r) >> 1;       tcost = ispossible(b, p, m, a);       if (tcost >= 0) {         l = m + 1;         cost = tcost;       } else         r = m;     }     if (l <= r) {       tcost = ispossible(b, p, r, a);       if (tcost >= 0) {         l = r + 1;         cost = tcost;       }     }     cout << l - 1 <<     << cost << endl;     return 0;   }