malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int n, k, limit, f[1010][1 << 2][2010], sta[1 << 2], ans;   int main() {     scanf( %d%d , &n, &k);     limit = (1 << 2) - 1;     sta[0] = 1;     sta[1] = 2;     sta[2] = 2;     sta[3] = 1;     for (int i = 0; i <= 3; i++) f[1][i][sta[i]] = 1;     for (int i = 1; i < n; i++)       for (int j = 0; j <= limit; j++)         for (int l = 1; l <= k; l++)           if (f[i][j][l]) {             for (int p = 0; p <= limit; p++) {               int temp = sta[p];               if (((p >> 0 & 1) == (j >> 0 & 1))) temp--;               if ((p >> 1 & 1) == (j >> 1 & 1)) temp--;               temp = max(0, temp);               f[i + 1][p][l + temp] = (f[i + 1][p][l + temp] + f[i][j][l]) % mod;             }           }     for (int i = 0; i <= limit; i++) ans = (ans + f[n][i][k]) % mod;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>      using namespace std;   const int N=3e5+10;   typedef long long ll;   int pos[N],a[N],q,n;   void  solve()   {    cin>>n>>q;    for(int i=1;i<=n;i++) cin>>a[i];    for(int i=n;i;i--)pos[a[i]]=i;    while(q--)    {     int x;     cin>>x;     cout<<pos[x]<<   ;     int t=pos[x];     pos[x]=1;     for(int i=1;i<=50;i++)     if(i!=x&&pos[i]<t)     pos[i]++;    }       }   int main()   {    int t=1;    while(t--)    {     solve();    }    //system( pause );    return 0;   }
#include <iostream>   #include <algorithm>      constexpr int N = 100005;      int n;   struct node {       long long a, b;   } a[N];      int main() {       std::ios::sync_with_stdio(false), std::cin.tie(nullptr);       std::cin >> n;       long long ans = 0;       for (int i = 1; i <= n; ++i) std::cin >> a[i].a >> a[i].b, ans += a[i].b;       std::sort(a + 1, a + n + 1, [](node a, node b) { return a.a < b.a; });       int now = 1;       long long max = a[1].a + a[1].b;       while (now <= n) {           int x = now + 1;           while (x <= n && a[x].a + a[x].b <= max) ++x;           if (x > n) break;           ans += std::max(a[x].a - max, 0ll);           max = a[x].a + a[x].b;           now = x;       }       std::cout << ans <<   n ;       return 0;   }
#include <bits/stdc++.h>   int n, m, k, flag, ans, cnt, p, q, w[1000005], f[1000005], g[1000005],       s[1000005];   int main() {     scanf( %d%d%d , &n, &m, &k);     w[0] = 1;     for (int i = 1; i <= n; i++) w[i] = w[i - 1] * 2 % 1000000007;     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       if (x > y) std::swap(x, y);       if (x + 1 == y)         f[x] = 1;       else if (x + k + 1 == y)         g[x] = 1, ++cnt;       else         flag = 1;     }     if (flag) {       puts( 0 );       return 0;     }     if (cnt == 0) {       for (int i = 1; i <= n; i++) {         if (i + k + 1 > n) continue;         int up = (i + k + k + 1 > n ? n - k - 1 : i + k);         int can = up - i + 1;         ans = (ans + w[can - 1]) % 1000000007;       }       ++ans;       printf( %d n , ans);       return 0;     }     for (int i = 1; i <= n; i++)       if (g[i]) q = i;     for (int i = n; i >= 1; i--)       if (g[i]) p = i;     if (p + k + 1 <= q) {       puts( 0 );       return 0;     }     for (int i = 1; i <= n; i++) s[i] = s[i - 1] + g[i];     for (int i = 1; i <= n; i++) {       if (g[i] || i + k + 1 > n) continue;       if (i >= p + k + 1 || i + k + 1 <= q) continue;       int cp = p, cq = q;       if (i < p) p = i;       if (i > q) q = i;       int up = (p + k + k + 1 > n ? n - k - 1 : p + k);       int can = up - i + 1 - (s[up] - s[i - 1]);       ans = (ans + w[can - 1]) % 1000000007;       q = cq, p = cp;     }     ++ans;     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int sum[5];   int n;   int main() {     cin >> n;     int res = 0;     for (int i = 1; i <= n; ++i) {       int t;       scanf( %d , &t);       if (t) sum[t]++;     }     int tmp = min(sum[1], sum[2]);     sum[3] += tmp;     res += tmp;     sum[2] -= tmp;     sum[1] -= tmp;     if (sum[1]) {       int t = sum[1] / 3;       res += t * 2;       sum[1] -= t * 3;       sum[3] += t;       if (sum[1]) {         if (sum[3] >= sum[1])           res += sum[1];         else {           if (sum[1] == 2) {             if (sum[4])               res += 2;             else {               printf( -1 n );               return 0;             }           } else {             if (sum[3])               res += 1;             else if (sum[4] >= 2)               res += 2;             else {               printf( -1 n );               return 0;             }           }         }       }     } else if (sum[2]) {       int t = sum[2] / 3;       res += t * 2;       sum[2] -= t * 3;       sum[3] += t * 2;       if (sum[2]) {         if (sum[4] >= sum[2])           res += sum[2];         else {           if (sum[2] == 2)             res += 2;           else {             if (sum[3] >= 2)               res += 2;             else {               printf( -1 n );               return 0;             }           }         }       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans, heavy;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s;     for (int i = 0; i <= (int)s.size() - 5; i++) {       if (s.substr(i, 5) ==  heavy ) {         heavy++;       } else if (s.substr(i, 5) ==  metal ) {         ans += heavy;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int K, N;   long double XX, YY, P[101], PP, arr[101][101], obj[101][2], EPS = 1e-9;   double calk(int n, int k) {     if (arr[n][k] != -1) return arr[n][k];     double retAns = 0;     if (n == 1 && k == 1)       arr[n][k] = P[1];     else if (n == 1 && k == 0)       arr[n][k] = 1 - P[1];     else if (n == 0 || k > n || k < 0)       arr[n][k] = 0;     else {       double v1 = calk(n - 1, k - 1) * P[n];       double v2 = calk(n - 1, k) * (1 - P[n]);       arr[n][k] = calk(n - 1, k - 1) * P[n] + calk(n - 1, k) * (1 - P[n]);     }     return arr[n][k];   }   double calcDist(double x, double y) {     return (x - XX) * (x - XX) + (y - YY) * (y - YY);   }   double calk2(double r) {     double retAns = 0;     for (int i = 0; i <= N; i++) {       for (int j = 0; j <= N; j++) arr[i][j] = -1;       if (i) {         double t = calcDist(obj[i][0], obj[i][1]);         if (r * r > EPS && t > r * r)           P[i] = exp(1.0 - t / (r * r));         else           P[i] = 1.0;       }     }     int g;     for (int k = K; k <= N; k++) retAns += calk(N, k);     return retAns;   }   double binS(double l, double r) {     if (fabs(l - r) < EPS) return l;     double mid = l + (r - l) / 2.0;     if (calk2(mid) > PP)       return binS(l, mid);     else       return binS(mid, r);   }   int main() {     cin >> N >> K;     double tp;     cin >> tp;     tp /= 1000;     tp = 1.0 - tp;     PP = tp;     cin >> XX >> YY;     for (int i = 1; i <= N; i++) cin >> obj[i][0] >> obj[i][1];     cout.setf(ios::fixed);     cout.precision(10);     cout << binS(0, 10000);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int N = 5000000;   const double eps = 1e-6;   int n, l, m, k, a[N], rev[N], res[N];   bool used[N];   complex<double> b[N], tmp[N];   pair<int, int> p[N];   vector<int> ans;   void fft(bool invert) {     for (int i = 0; i < l; i++) tmp[rev[i]] = b[i];     for (int i = 0; i < l; i++) b[i] = tmp[i];     for (int r = 1; r <= k; r++) {       for (int i = 0; i < l; i += (1 << r)) {         for (int j = i; j < i + (1 << (r - 1)); j++) {           double ang;           if (!invert)             ang = 2.0 * (j - i) * pi / (1 << r);           else             ang = -2.0 * (j - i) * pi / (1 << r);           complex<double> w(cos(ang), sin(ang));           complex<double> t1 = b[j], t2 = b[j + (1 << (r - 1))];           b[j] = t1 + w * t2;           b[j + (1 << (r - 1))] = t1 - w * t2;         }       }     }     if (invert) {       for (int i = 0; i < l; i++) b[i] /= l;     }   }   int main() {     scanf( %d%d , &n, &m);     memset(used, false, sizeof(used));     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) used[a[i]] = true;     m++;     l = 1;     k = 0;     for (int i = 1; i <= 20; i++)       if (l < m) {         l *= 2;         k++;       } else         break;     l *= 2;     k++;     for (int i = 0; i < n; i++) b[a[i]] = complex<double>(1, 0);     for (int i = 0; i < l; i++) {       int mask = 0;       for (int j = 0; j < k; j++)         if (i & (1 << j)) mask |= 1 << (k - j - 1);       rev[i] = mask;     }     fft(0);     for (int i = 0; i < l; i++) b[i] *= b[i];     fft(1);     for (int i = 0; i < l; i++) res[i] = b[i].real() + 0.5;     for (int i = 1; i < m; i++) {       if ((!res[i]) && (used[i]))         ans.push_back(i);       else if ((res[i]) && (!used[i])) {         cout <<  NO ;         return 0;       }     }     cout <<  YES  << endl;     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-10;   const int MOD = 998244353;   const int INF = 0x3f3f3f3f;   const int maxn = 1e3 + 10;   const int maxm = 2e5 + 10;   char s[maxn];   int len, arr[maxn];   pair<int, long long> dq[maxn];   int main() {     scanf( %d%s , &len, s + 1);     for (int i = 1; i <= len; ++i) s[len + i] = s[i];     int ans = 0;     pair<int, long long> pos;     for (int i = 1; i <= len; ++i)       for (int j = i; j <= len; ++j) {         int cnt = 0;         swap(s[i], s[j]);         swap(s[i + len], s[j + len]);         int top = 500, bk = 499;         for (int k = 1; k <= len * 2; ++k) {           if (s[k] ==  ( )             arr[k] = ++cnt;           else             arr[k] = --cnt;         }         for (int k = 1; k <= len; ++k) {           while (bk >= top && dq[bk].first > arr[k]) --bk;           dq[++bk] = {arr[k], k};         }         int pre = 0, res = 0;         for (int k = 1; k <= len; ++k) {           while (dq[top].second < k) ++top;           while (bk >= top && dq[bk].first >= arr[k + len - 1]) --bk;           dq[++bk] = {arr[k + len - 1], k + len - 1};           if (dq[top].first - pre >= 0 && arr[k + len - 1] - pre == 0) ++res;           pre = arr[k];         }         if (ans < res) {           ans = res;           pos = {i, j};         }         swap(s[i], s[j]);         swap(s[i + len], s[j + len]);       }     printf( %d n , ans);     if (pos.first == 0) pos = {1, 1};     printf( %d %d n , pos.first, pos.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int a[200005], n, len = 1 << 18;   int mx1[1 << 18], mx2[1 << 18], fa[200005], w1[200005], w2[200005];   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void add(int x, int w) {     if (find(w) != find(mx1[x]) && a[w] > a[mx1[x]])       mx2[x] = mx1[x], mx1[x] = w;     else if (find(w) != find(mx1[x]) && a[w] > a[mx2[x]])       mx2[x] = w;   }   int query(int x) {     int t = (len - 1) ^ a[x];     if (mx1[t] && find(mx1[t]) != find(x)) return mx1[t];     if (mx2[t] && find(mx2[t]) != find(x)) return mx2[t];     return 0;   }   int merge(int x, int y) {     if (y == 0) return 0;     y = find(y);     if (x == y) return 0;     fa[x] = y;     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]), ans -= a[i];     ++n;     a[0] = -1;     for (int i = 1; i <= n; ++i) fa[i] = i;     while (1) {       for (int i = 0; i < len; ++i) mx1[i] = mx2[i] = 0;       for (int i = 1; i <= n; ++i) add(a[i], i);       for (int i = 0; i < 18; ++i)         for (int j = 0; j < len; ++j)           if (j & (1 << i)) {             add(j, mx1[j ^ (1 << i)]);             add(j, mx2[j ^ (1 << i)]);           }       for (int i = 1; i <= n; ++i) w1[i] = -1;       for (int i = 1; i <= n; ++i) {         int t = query(i), x = find(i);         if (t != 0 && a[i] + a[t] > w1[x]) w1[x] = a[i] + a[t], w2[x] = t;       }       int f = 0;       for (int i = 1; i <= n; ++i)         if (find(i) == i && merge(i, w2[i])) ans += w1[i], f = 1;       if (!f) break;     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     int start = 0, ends = n - 1;     while (start != ends) {       if (arr[ends] < arr[start]) {         reverse(arr + start, arr + ends + 1);         break;       } else if (ends == n && arr[ends] > arr[ends - 1]) {         ends--;         start++;       } else if (arr[ends] < arr[ends + 1] && arr[ends] < arr[ends - 1]) {         if (arr[ends] > arr[start]) {           start++;           ends++;         }       } else if (arr[ends] > arr[ends + 1] && arr[ends] < arr[ends - 1]) {         ends++;         start++;       }       ends--;     }     for (int i = 1; i < n; i++) {       if (arr[i] < arr[i - 1]) {         cout <<  no ;         return 0;       }     }     cout <<  yes  << endl          << min(ends + 1, start + 1) <<     << max(ends + 1, start + 1);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, l;     std::cin >> n >> l;     int *num = new int[n];     int i;     for (i = 0; i < l; i++) {       num[i] = i + 97;     }     while (i < n) {       num[i] = num[i - l];       i++;     }     for (int i = 0; i < n; i++) std::cout << (char)(num[i]);   }
#include <bits/stdc++.h>   using namespace std;   struct comp {     double re, im;     comp(double x = 0, double y = 0) : re(x), im(y) {}     comp operator+(const comp& a) { return comp(re + a.re, im + a.im); }     comp operator-(const comp& a) { return comp(re - a.re, im - a.im); }     comp operator*(const comp& a) {       return comp(re * a.re - im * a.im, re * a.im + im * a.re);     }   };   const double pi = acos(-1);   void fft(vector<comp>& x) {     int n = x.size();     for (int i = 1, k = 0; i < n; ++i) {       for (int bit = n >> 1; (k ^= bit) < bit; bit >>= 1) {       }       if (i < k) {         swap(x[i], x[k]);       }     }     for (int k = 1; k < n; k <<= 1) {       comp wlen(cos(pi / k), sin(pi / k));       for (int i = 0; i < n; i += (k << 1)) {         comp w(1);         for (int j = 0; j < k; ++j) {           comp tmp = w * x[i + j + k];           x[i + j + k] = x[i + j] - tmp;           x[i + j] = x[i + j] + tmp;           w = w * wlen;         }       }     }   }   template <class T>   vector<T> mul(vector<T>& a, vector<T>& b) {     int n = max(a.size(), b.size());     int lg = 31 - __builtin_clz(n);     n = 1 << (lg + 1 + (n != (1 << lg)));     vector<comp> fa(n), fb(n);     for (int i = 0; i < a.size(); ++i) {       fa[i] = a[i];     }     for (int i = 0; i < b.size(); ++i) {       fb[i] = b[i];     }     fft(fa);     if (a == b) {       fb = fa;     } else {       fft(fb);     }     for (int i = 0; i < n; ++i) {       fa[i] = fa[i] * fb[i];     }     fft(fa);     reverse(fa.begin() + 1, fa.end());     vector<T> c(n);     for (int i = 0; i < n; ++i) {       c[i] = (T)(fa[i].re / n + (fa[i].re > 0 ? 0.5 : -0.5));     }     return c;   }   const int N = 5e5 + 5;   bool ok[N];   int ans[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n, x, y;     cin >> n >> x >> y;     ++n;     vector<int> a(x + 1);     for (int i = 0; i < n; ++i) {       int z;       cin >> z;       a[z] = 1;     }     auto b = a;     reverse(b.begin(), b.end());     auto c = mul(a, b);     for (int i = 1; i <= x; ++i)       if (c[i + x]) ok[i + y] = true;     for (int i = 1; i < N; ++i) {       if (!ans[i]) ans[i] = -1;       if (!ok[i]) continue;       for (int j = i; j < N; j += i) ans[j] = 2 * i;     }     int q;     cin >> q;     while (q--) {       int z;       cin >> z;       cout << ans[z / 2] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000010LL;   const int mod = 1000000007;   const int MAXN = 100010;   int n, m, u, v, x, y, t, a, b, ans, node, cnt;   bool ok[MAXN];   bool mark[MAXN];   vector<int> G[MAXN];   vector<int> out;   void dfs(int node, int par) {     mark[node] = true;     cnt -= ok[node];     ok[node] ^= 1;     for (int v : G[node]) {       if (mark[v]) continue;       out.push_back(v);       dfs(v, node);       out.push_back(node);       ok[node] ^= 1;     }     if (ok[node] && par) {       out.push_back(par);       out.push_back(node);       ok[par] ^= 1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     while (m--) {       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       cin >> ok[i];       if (ok[i]) cnt++;       if (!node && ok[i]) node = i;     }     if (!node) return cout << 0 <<   n , 0;     ;     dfs(node, 0);     if (cnt) return cout << -1 <<   n , 0;     ;     if (!ok[node])       cout << out.size() + 1 << endl << node <<    ;     else       cout << out.size() << endl;     for (int i : out) cout << i <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string a[1000], b[1000];     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];     }     for (int i = 0; i < m; i++) {       string cmd, ip, tip;       cin >> cmd >> ip;       for (int i = 0; i < ip.size() - 1; i++) tip += ip[i];       for (int i = 0; i < n; i++) {         if (tip.compare(b[i]) == 0)           cout << cmd <<     << ip <<   #  << a[i] <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, ans = 1 << 30;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= k - 1; i++)       if (n % i == 0) ans = min(ans, k * n / i + i);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, j;   const double eps = 1e-9;   struct nd {     double x, y;   };   nd operator-(nd x, nd y) { return (nd){x.x - y.x, x.y - y.y}; }   bool cmp(nd x, nd y) {     if (x.x == y.x) return x.y < y.y;     return x.x < y.x;   }   double dis(nd x, nd y) { return abs(x.x - y.x) + abs(x.y - y.y); }   double dis2(nd x, nd y) {     return sqrt((x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y));   }   double crs(nd x, nd y) { return x.x * y.y - x.y * y.x; }   vector<nd> all, cov;   nd stk[2000005];   int tp;   void update1(nd x) {     if (0 <= x.x && x.x <= 1e5 && 0 <= x.y && x.y <= 1e5) all.push_back(x);   }   void update2(nd p, double r, nd x) {     if (dis(p, x) <= r) all.push_back(x);   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       double x, y, r;       scanf( %lf%lf%lf , &x, &y, &r);       if (x + r <= 1e5)         update1((nd){x + r, y});       else {         update1((nd){1e5, y - (r - (1e5 - x))});         update1((nd){1e5, y + (r - (1e5 - x))});       }       if (x - r >= 0)         update1((nd){x - r, y});       else {         update1((nd){0, y - (r - x)});         update1((nd){0, y + (r - x)});       }       if (y + r <= 1e5)         update1((nd){x, y + r});       else {         update1((nd){x - (r - (1e5 - y)), 1e5});         update1((nd){x + (r - (1e5 - y)), 1e5});       }       if (y - r >= 0)         update1((nd){x, y - r});       else {         update1((nd){x - (r - y), 0});         update1((nd){x + (r - y), 0});       }       update2((nd){x, y}, r, (nd){0, 0});       update2((nd){x, y}, r, (nd){0, 1e5});       update2((nd){x, y}, r, (nd){1e5, 0});       update2((nd){x, y}, r, (nd){1e5, 1e5});     }     sort(all.begin(), all.end(), cmp);     stk[tp = 1] = all[0];     for (i = 1; i < all.size(); i++) {       if (all[i].x == all[i - 1].x && all[i].y == all[i - 1].y) continue;       while (tp > 1 && crs(stk[tp] - stk[tp - 1], all[i] - stk[tp]) > -eps) tp--;       stk[++tp] = all[i];     }     for (i = 1; i < tp; i++) cov.push_back(stk[i]);     reverse(all.begin(), all.end());     stk[tp = 1] = all[0];     for (i = 1; i < all.size(); i++) {       if (all[i].x == all[i - 1].x && all[i].y == all[i - 1].y) continue;       while (tp > 1 && crs(stk[tp] - stk[tp - 1], all[i] - stk[tp]) > -eps) tp--;       stk[++tp] = all[i];     }     for (i = 1; i < tp; i++) cov.push_back(stk[i]);     double ans = -1e18;     int res = 0;     for (i = 0; i < cov.size(); i++) {       int j = (i + 1) % cov.size();       int k = (i + 2) % cov.size();       double tmp = dis2(cov[i], cov[j]) * dis2(cov[i], cov[k]) *                    dis2(cov[j], cov[k]) / 4 /                    abs(crs(cov[j] - cov[i], cov[k] - cov[i]) / 2);       if (tmp > ans) {         ans = tmp;         res = i;       }     }     printf( %.0f %.0f n , cov[res].x, cov[res].y);     printf( %.0f %.0f n , cov[(res + 1) % cov.size()].x,            cov[(res + 1) % cov.size()].y);     printf( %.0f %.0f n , cov[(res + 2) % cov.size()].x,            cov[(res + 2) % cov.size()].y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > ps, is, psum(100001), isum(100001);   long long m, n, d;   class cmp {    public:     bool operator()(pair<long long, long long> &a,                     pair<long long, long long> &b) {       return a.first > b.first || (a.first == b.first && a.second < b.second);     }   };   long long bsearch(long long w, long long lo, long long hi) {     long long mid = lo + (hi - lo) / 2;     if (lo > hi) return -1;     if (lo == hi) {       return (isum[lo].second <= w) ? lo : -1;     }     if (isum[mid].second > w) return bsearch(w, lo, mid);     long long ret = bsearch(w, mid + 1, hi);     return ret == -1 ? mid : ret;   }   int main() {     long long i, j, t1, t2;     cin >> n >> m >> d;     for (i = 0; i < n; i++) {       cin >> t1 >> t2;       ps.push_back(pair<long long, long long>(t1, t2));     }     for (i = 0; i < m; i++) {       cin >> t1 >> t2;       is.push_back(pair<long long, long long>(t1, t2));     }     sort(ps.begin(), ps.end(), cmp());     sort(is.begin(), is.end(), cmp());     psum[0] = pair<long long, long long>(0, 0),     isum[0] = pair<long long, long long>(0, 0);     for (i = 1; i <= n; i++) {       j = i - 1;       psum[i] = pair<long long, long long>(ps[j].first + psum[i - 1].first,                                            ps[j].second + psum[i - 1].second);     }     for (i = 1; i <= m; i++) {       j = i - 1;       isum[i] = pair<long long, long long>(is[j].first + isum[i - 1].first,                                            is[j].second + isum[i - 1].second);     }     long long ans = 0;     for (i = 1; i <= n; i++) {       pair<long long, long long> tp = psum[i];       long long ind = bsearch(d - tp.second, 1, m);       if (ind == -1) break;       ans = max(ans, tp.first + isum[ind].first);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     long long arr[n], ans[n];     for (long long i = 0; i < n; i++) arr[i] = 1;     ans[n - 1] = 1;     for (long long i = 2; i <= n; i++) {       arr[n - 1] = i;       cout <<  ?  ;       for (long long i = 0; i < n; i++) cout << arr[i] <<    ;       cout <<   n ;       cout << flush;       long long k;       cin >> k;       if (!k) {         ans[n - 1] = n - i + 2;         break;       }     }     long long i = 1;     for (long long i = 0; i < n; i++) arr[i] = ans[n - 1];     while (i <= n) {       if (i == ans[n - 1]) {         i++;         continue;       }       arr[n - 1] = i;       cout <<  ?  ;       for (long long i = 0; i < n; i++) cout << arr[i] <<    ;       cout <<   n ;       cout << flush;       long long k;       cin >> k;       ans[k - 1] = i;       i++;     }     cout <<  !  ;     for (long long i = 0; i < n; i++) cout << ans[i] <<    ;     cout <<   n ;   }