malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T a) {     return a * a;   }   #pragma comment(linker,  /STACK:16777216 )   int n;   char s[105];   string str;   int main() {     gets(s);     str = s;     n = strlen(s);     for (int i = n - 1; i > 0; --i)       for (int j = 0; j <= n - i; ++j)         for (int k = j + 1; k <= n - i; ++k)           if (str.substr(j, i) == str.substr(k, i)) {             printf( %d , i);             return 0;           }     printf( 0 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 205;   int read() {     int x = 0, f = 1;     char ch;     while (!isdigit(ch = getchar())) (ch ==  - ) && (f = -f);     for (x = ch ^ 48; isdigit(ch = getchar());          x = (x << 3) + (x << 1) + (ch ^ 48))       ;     return x * f;   }   vector<int> vec[N];   int n, s, t, tim, cnt = 1, a[N], head[N], vis[N], level[N], is[20010];   struct edge {     int v, w, nxt;   } e[N * N];   void add(int x, int y, int w) {     e[++cnt] = (edge){y, w, head[x]};     head[x] = cnt;     e[++cnt] = (edge){x, 0, head[y]};     head[y] = cnt;   }   void init(int n) {     is[1] = 1;     for (int i = 2; i <= n; ++i) {       if (is[i]) continue;       for (int j = i + i; j <= n; j += i) is[j] = 1;     }   }   int bfs() {     queue<int> Q;     Q.push(s);     memset(level, 0, sizeof(level));     level[s] = 1;     while (!Q.empty()) {       int x = Q.front();       Q.pop();       for (int i = head[x]; i; i = e[i].nxt) {         int v = e[i].v, w = e[i].w;         if (w && !level[v]) level[v] = level[x] + 1, Q.push(v);       }     }     return level[t] != 0;   }   int dfs(int x, int flow) {     if (x == t || !flow) return flow;     int up = 0;     for (int i = head[x]; i; i = e[i].nxt) {       int v = e[i].v, w = e[i].w;       if (w && level[v] == level[x] + 1) {         int tmp = dfs(v, min(flow, w));         e[i].w -= tmp, e[i ^ 1].w += tmp;         flow -= tmp, up += tmp;         if (!flow) break;       }     }     if (!up) level[x] = 0;     return up;   }   int Dinic() {     int maxflow = 0;     while (bfs()) maxflow += dfs(s, 2e9);     return maxflow;   }   void find(int x) {     vis[x] = 1;     vec[tim].push_back(x);     for (int i = head[x]; i; i = e[i].nxt)       if (!vis[e[i].v] && e[i | 1].w == 1) find(e[i].v);   }   int main() {     n = read();     s = 0;     t = n + 1;     init(20000);     for (int i = 1; i <= n; ++i) a[i] = read();     for (int i = 1; i <= n; ++i)       if (a[i] & 1)         add(i, t, 2);       else         add(s, i, 2);     for (int i = 1; i <= n; ++i) {       if (a[i] & 1) continue;       for (int j = 1; j <= n; ++j)         if (!is[a[i] + a[j]]) add(i, j, 1);     }     if (Dinic() != n) return puts( Impossible ), 0;     for (int i = 1; i <= n; ++i)       if (!vis[i]) ++tim, find(i);     printf( %d n , tim);     for (int i = 1; i <= tim; ++i) {       printf( %d  , vec[i].size());       for (int j = 0; j < vec[i].size(); ++j) printf( %d  , vec[i][j]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const maxn = (int)1e4 + 111;   int const inf = (1 << 30) - 1;   int k;   int a[4];   int t[4];   int d[maxn][4];   int first[maxn][4];   int main() {     cin >> k;     for (int i = 1; i <= 3; i++) cin >> a[i];     for (int i = 1; i <= 3; i++) cin >> t[i];     for (int j = 1; j <= 3; j++) {       for (int i = 1; i <= k; i++) {         int v = -1;         for (int q = 1; q <= a[j]; q++) {           if (v == -1 || first[q][j] < first[v][j]) {             v = q;           }         }         d[i][j] = max(d[i][j - 1], first[v][j]) + t[j];         first[v][j] = d[i][j];       }     }     cout << d[k][3] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, qa, qb, answer;   int i, j, p, k, lcm, d;   int dist[1000000];   char inq[1000000];   int gcd(int x, int y) {     if ((x % y) == 0) return y;     return gcd(y, x % y);   }   void ComputeDist() {     for (i = 0; i <= lcm; i++) {       dist[i] = lcm + 1;       inq[i] = 0;     }     dist[0] = 0;     queue<int> q;     q.push(0);     inq[0] = 1;     while (q.size() > 0) {       i = q.front();       q.pop();       inq[i] = 0;       if (i + 1 <= lcm && (1 + dist[i] < dist[i + 1])) {         dist[i + 1] = 1 + dist[i];         if (!inq[i + 1]) {           q.push(i + 1);           inq[i + 1] = 1;         }       }       for (j = 2; j <= k; j++)         if (i % j == 0) {           for (p = 1; p < j; p++)             if (i + p <= lcm && (1 + dist[i] < dist[i + p])) {               dist[i + p] = 1 + dist[i];               if (!inq[i + p]) {                 q.push(i + p);                 inq[i + p] = 1;               }             }         }     }   }   void ComputeDist2(int end, int start) {     for (i = 0; i <= start; i++) {       dist[i] = start + 1;       inq[i] = 0;     }     dist[start] = 0;     queue<int> q;     q.push(start);     inq[start] = 1;     while (q.size() > 0) {       i = q.front();       q.pop();       inq[i] = 0;       if (i - 1 >= end && (1 + dist[i] < dist[i - 1])) {         dist[i - 1] = 1 + dist[i];         if (!inq[i - 1]) {           q.push(i - 1);           inq[i - 1] = 1;         }       }       for (j = 2; j <= k; j++)         if (i % j > 0) {           p = i % j;           if (i - p >= end && (1 + dist[i] < dist[i - p])) {             dist[i - p] = 1 + dist[i];             if (!inq[i - p]) {               q.push(i - p);               inq[i - p] = 1;             }           }         }     }   }   int main() {     scanf( %I64d %I64d %d , &a, &b, &k);     lcm = 1;     for (i = 2; i <= k; i++) {       d = gcd(i, lcm);       lcm *= (i / d);     }     ComputeDist();     qa = a / lcm;     qb = b / lcm;     answer = 0;     if (qa > qb + 1) {       answer += dist[a % lcm];       answer += dist[lcm] * (qa - qb - 1);       a = (qb + 1) * lcm;     }     ComputeDist2(b % lcm, a - qb * lcm);     answer += dist[b % lcm];     printf( %I64d n , answer);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 100005, LOG = 22;   int n, fth[MaxN], poz[MaxN], fr[MaxN], w[MaxN], sz[MaxN], nrzone = 1;   pair<int, int> v[MaxN];   int Find(int x) {     if (!fth[x]) return x;     return fth[x] = Find(fth[x]);   }   void Join(int x, int y) {     int X = Find(x), Y = Find(y);     if (X != Y) fth[X] = Y;   }   void Solve(int a, int b) {     if (a < b) {       fr[sz[Find(a)]]--;       fr[sz[Find(b)]]--;       nrzone--;       fr[sz[Find(a)] + sz[Find(b)]]++;       sz[Find(b)] += sz[Find(a)];       Join(a, b);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> v[i].first;       w[i] = v[i].first;       v[i].second = i;     }     if (n == 1) {       cout << v[1].first + 1 <<   n ;       return 0;     }     sort(v + 1, v + n + 1);     v[n + 1].first = v[n].first + 1;     for (int i = 1; i <= n; ++i) {       poz[i] = v[i].second;       w[v[i].second] = i;     }     int maxk = 1, nrzonemax = 1;     fr[1] = 1;     sz[1] = 1;     for (int k = 2; k < n; ++k) {       int pozz = poz[k];       fr[1]++;       nrzone++;       sz[k] = 1;       if (pozz != 1) Solve(w[pozz - 1], k);       if (pozz != n) Solve(w[pozz + 1], k);       if (fr[sz[Find(k)]] == nrzone && nrzone > nrzonemax) {         maxk = k;         nrzonemax = nrzone;       }     }     cout << v[maxk].first + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000006;   const long long MOD = 1000000007;   struct Query {     int a, t, x, id;   } query[MAXN];   map<int, int> cnt;   int n, ans[MAXN], qcnt;   void solve(int l, int r) {     ;     if (l != r - 1) {       int mid = (l + r) >> 1;       solve(l, mid);       solve(mid, r);       cnt.clear();       int lp = l, rp = mid;       while (rp < r) {         if (lp == mid || query[lp].t > query[rp].t) {           if (query[rp].a == 3) {             ;             ans[query[rp].id] += cnt[query[rp].x];           }           rp++;         } else {           if (query[lp].a == 1) {             cnt[query[lp].x]++;           } else if (query[lp].a == 2) {             cnt[query[lp].x]--;           }           lp++;         }       };       sort(query + l, query + r, [&](Query q1, Query q2) { return q1.t < q2.t; });     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     cin >> n;     for (int i = 0; i < n; i++) {       int a, t, x;       cin >> a >> t >> x;       query[i] = {a, t, x, qcnt};       ;       if (a == 3) {         qcnt++;       }     }     solve(0, n);     for (int i = 0; i < qcnt; i++) {       cout << ans[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int m;   int a[1 << 7];   int min_k, max_k;   bool ok(int ask) {     int need = 0;     for (int i = 0; i < n; i++) {       if (a[i] > ask) {         return false;       }       if (ask > a[i]) {         need += ask - a[i];       }     }     if (need >= m) {       return true;     }     return false;   }   void read(void) {     cin >> n;     cin >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }   }   void solve(void) {     for (int i = 0; i < n; i++) {       max_k = max(max_k, a[i] + m);     }     for (int k = 1; k <= 10100; k++) {       if (ok(k)) {         min_k = k;         break;       }     }   }   void print(void) { cout << min_k <<     << max_k << endl; }   int main() {     read();     solve();     print();     return 0;   }
#include <bits/stdc++.h>   constexpr int Maxn = 1e5 + 7;   constexpr int Mod = 1e9 + 7;   int fac[Maxn], ifac[Maxn];   inline int fpm(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = 1LL * res * a % Mod;       a = 1LL * a * a % Mod;       b >>= 1;     }     return res;   }   inline int C(int n, int m) {     if (n < 0 || m < 0 || n < m) return 0;     return 1LL * fac[n] * ifac[m] % Mod * ifac[n - m] % Mod;   }   std::unordered_map<int, int> cnt, mp;   int n, m, k, f[Maxn], p[Maxn], s[Maxn];   int solve(int x) {     if (mp.count(x)) return mp[x];     int res = 0;     for (int i = 0; i <= m; ++i) res = (res + 1LL * p[i] * s[i + x] % Mod) % Mod;     return mp[x] = res;   }   int main() {     scanf( %d%d , &n, &k);     fac[0] = 1;     for (int i = 1; i <= n; ++i) fac[i] = 1LL * i * fac[i - 1] % Mod;     ifac[n] = fpm(fac[n], Mod - 2);     for (int i = n - 1; i >= 0; --i) ifac[i] = 1LL * (i + 1) * ifac[i + 1] % Mod;     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       ++cnt[x];     }     f[0] = k - 1;     for (int i = 1; i < n; ++i) {       int p = 1LL * i * fpm(n, Mod - 2) % Mod;       int q = 1LL * (n - i) * fpm(n, Mod - 2) % Mod * fpm(k - 1, Mod - 2) % Mod;       f[i] = (1LL * p * f[i - 1] % Mod + 1) * fpm(q, Mod - 2) % Mod;     }     for (int i = n; i; --i) s[i - 1] = (s[i] + f[i - 1]) % Mod;     m = cnt[-1];     for (int i = 0; i <= m; ++i)       p[i] =           1LL * C(m, i) * fpm(k - 1, m - i) % Mod * fpm(fpm(k, m), Mod - 2) % Mod;     int res = 0, tot = k;     for (auto x : cnt)       if (x.first != -1) {         res = (res + solve(x.second)) % Mod;         --tot;       }     res = (res + 1LL * tot * solve(0) % Mod) % Mod;     res = (res - 1LL * (k - 1) * s[0] % Mod + Mod) % Mod;     printf( %d n , 1LL * res * fpm(k - 1, Mod - 2) % Mod);   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {   y:     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     ;     ll n = 0, k = 0;     cin >> n >> k;     ll a = 0, b = 0;     ll sum = 0;     ll pos = 0;     for (int i = 0; i < k; ++i) {       cin >> a >> b;       sum += b;       pos += a * b;     }     if (sum < n)       cout << 1 <<   n ;     else {       if (!(pos % n == (n * (n - 1)) / 2 % n))         cout << -1 <<   n ;       else         cout << 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int a, n;     cin >> n >> s;     for (int i = 0; i < n; ++i) {       for (int j = 1; j < n + 1; ++j) {         if (i + 4 * j >= n) break;         if (s[i] ==  *  && s[i + j] ==  *  && s[i + 2 * j] ==  *  &&             s[i + 3 * j] ==  *  && s[i + 4 * j] ==  * ) {           printf( yes n );           return 0;         }       }     }     printf( no n );   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     vector<vector<vector<int>>> dp(n + 1,                                    vector<vector<int>>(m + 1, vector<int>(2, 0)));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         dp[i][j][1] = dp[i][j - 1][0] + 1;         dp[i][j][0] = dp[i - 1][j][1] + 1;       }     int ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         ans += dp[i][j][0] + dp[i][j][1];       }     ans -= n * m;     int q;     cin >> q;     vector<vector<int>> a(n, vector<int>(m, 1));     auto calc_len = [&](int x, int y, int dx, int dy) {       int res = 0;       while (1) {         x += dx;         y += dy;         if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] == 0) {           break;         }         res++;         swap(dx, dy);       }       return res;     };     while (q--) {       int i, j;       cin >> i >> j;       i--, j--;       {         int x = calc_len(i, j, -1, 0);         int y = calc_len(i, j, 0, 1);         ans += (a[i][j] == 1 ? -1 : 1) * ((x + 1) * (y + 1));       }       {         int x = calc_len(i, j, 0, -1);         int y = calc_len(i, j, 1, 0);         ans += (a[i][j] == 1 ? -1 : 1) * ((x + 1) * (y + 1));       }       ans += (a[i][j] == 1 ? 1 : -1);       a[i][j] ^= 1;       cout << ans << endl;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T = 1;     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, a, ans;   set<pair<int, int> > s;   int x, m;   bool used[1000000];   int solve(int x) { return (x + 1) / (a + 1); }   void go(int x) {     set<pair<int, int> >::iterator it = s.upper_bound(make_pair(x, 1000000000));     --it;     pair<int, int> cur = *it;     s.erase(it);     ans -= solve(cur.second - cur.first + 1);     if (x != cur.first) {       ans += solve(x - cur.first);       s.insert(make_pair(cur.first, x - 1));     }     if (x != cur.second) {       ans += solve(cur.second - x);       s.insert(make_pair(x + 1, cur.second));     }   }   int main() {     cin >> n >> k >> a;     s.insert(make_pair(1, n));     ans = solve(n);     cin >> m;     for (int i = 1; i <= m; i++) {       cin >> x;       if (used[x]) continue;       used[x] = 1;       go(x);       if (ans < k) {         cout << i;         return 0;       }     }     cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   const int N =9999999;   const double pi=acos(-1);       int n,t,ans,a[N],k,s1,s2;   int main(){    cin>>t;    while(t--){     cin>>n>>k;     if(n%2==1)cout<<((k-1)+((k-1))/(n/2))%n+1<<endl;     else cout<<(k-1)%n+1<<endl;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long int StrToInt(string& s) {     long long int ans = 0;     for (int i = 0; i < s.size(); i++) ans = ans * 10 + s[i] -  0 ;     return ans;   }   vector<long long int> v, t, pref;   long long int bp(long long int mo) {     long long int l = 0, r = v.size(), m;     while (r - l > 1) {       m = (r + l) / 2;       if (v[m] > mo)         r = m;       else         l = m;     }     return l;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int n;     cin >> n;     v.resize(n);     t.resize(n);     pref.resize(n + 1);     for (int i = 0; i < n; i++) cin >> v[i];     for (int j = 0; j < n; j++) cin >> t[j];     pref[0] = 0;     for (int i = 1; i <= n; ++i) {       pref[i] = pref[i - 1] + t[i - 1];       v[i - 1] += pref[i - 1];     }     sort(v.begin(), v.end());     long long int ans = 0;     for (int i = 0; i < n; i++) {       ans = 0;       long long int m = upper_bound(v.begin(), v.end(), pref[i]) - v.begin();       long long int mm = upper_bound(v.begin(), v.end(), pref[i + 1]) - v.begin();       ans += (i - mm + 1) * t[i];       for (int j = m; j < mm; j++) ans += v[j] - pref[i];       cout << ans <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 10;   string rs;   int pre[maxn];   void matchprefix() {     int n = rs.length();     pre[0] = 0;     int k = 0;     for (int i = 1; i < n; i++) {       while (k > 0 && rs[k] != rs[i]) k = pre[k - 1];       if (rs[k] == rs[i]) k++;       pre[i] = k;     }   }   int z[maxn];   void Z_function() {     int n = rs.length();     z[0] = 0;     int L = 0, R = 0;     for (int i = 1; i < n; i++) {       z[i] = 0;       if (i <= R) {         if (z[i - L] < R - i + 1)           z[i] = z[i - L];         else {           z[i] = min(z[i - L], R - i + 1);           while (i + z[i] < n && rs[i + z[i]] == rs[z[i]]) z[i]++;           L = i;           R = i + z[i] - 1;         }       } else {         while (i + z[i] < n && rs[i + z[i]] == rs[z[i]]) z[i]++;         L = i;         R = i + z[i] - 1;       }     }   }   int main() {     string s, t;     getline(cin, s);     getline(cin, t);     int n = s.length();     if (n != t.length()) {       cout <<  -1 -1 ;       return 0;     }     rs = s;     reverse(rs.begin(), rs.end());     rs.push_back(  n );     rs += t;     matchprefix();     rs = t +   n  + s +   n ;     Z_function();     int ansi = -1, ansj = -1;     for (int i = 0; i + 1 < n; i++) {       if (s[i] != t[n - 1 - i]) break;       int len_0_i = i + 1;       int len_i_j = z[n + i + 2];       int len_j_n = pre[n + n - i - 1];       if (len_j_n > 0 && len_0_i + len_i_j + len_j_n >= n) {         ansi = i;         ansj = n - len_j_n;       }     }     cout << ansi <<     << ansj;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s1;     int count = 0;     cin >> s1;     char c = s1[0];     for (int i = 0; i < s1.length(); i++) {       if (s1[i] == c)         count++;       else if (s1[i] > c) {         count = 1;         c = s1[i];       }     }     cout << string(count, c);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   #pragma GCC optimize( move-loop-invariants )   std::mt19937 rnd(237);   using namespace std;   using ll = long long;   using ld = long double;   const int inf = 1e9 + 8;   const ll linf = 4e18 + 18;   const int N = 1e6 + 6;   const double pi = acos(-1.0);   int n;   vector<int> a, b, p, pp;   vector<vector<int>> g;   vector<ll> sum;   ll ans = 0;   void dfs(int v, int par = -1) {     sum[v] = a[v];     for (auto &u : g[v]) {       if (u != par) dfs(u, v);     }     if (sum[v] > 0) {       if (~par) sum[par] += sum[v];       p.push_back(v);     } else       pp.push_back(v);     ans += sum[v];   }   void solve() {     cin >> n;     a.resize(n);     b = a;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     g.assign(n, {});     vector<int> indeg(n, 0);     for (int i = 0; i < n; ++i) {       cin >> b[i];       if (~b[i]) {         g[b[i] - 1].push_back(i);         indeg[i]++;       }     }     sum.resize(n);     for (int i = 0; i < n; ++i) {       if (!indeg[i]) dfs(i);     }     cout << ans <<   n ;     for (auto &x : p) cout << x + 1 <<    ;     for (int i = (int)pp.size() - 1; ~i; --i) cout << pp[i] + 1 <<    ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int test_case = 1;     for (int t = 0; t < test_case; ++t) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int f[3][4] = {{0, 3, 1, 2}, {}, {0, 2, 3, 1}};   void solve(long long x, int y) {     if (y == 1) {       printf( %lld n , x);       return;     }     long long ans = 0, p = 1;     while (x) {       ans += f[y][x % 4] * p;       x >>= 2, p <<= 2;     }     printf( %lld n , ans);   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long n;       scanf( %lld , &n);       long long j = 1, a;       while (j <= n) j <<= 2;       j >>= 2;       if (j + 2 >= n)         a = j;       else         a = j + (n - j) / 3;       solve(a, n % 3);     }   }
#include <bits/stdc++.h>   using namespace std;   string s[1000 + 5];   int nsc[1000 + 5], nsl[1000 + 5];   int main() {     int n, m;     cin >> n >> m;     int i, j, z;     for (i = 0; i < n; i++) cin >> s[i];     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (s[i][j] ==  * ) nsl[i]++, nsc[j]++;     long long ans = 0;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (s[i][j] ==  * ) ans += 1LL * (nsl[i] - 1) * (nsc[j] - 1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   inline void chmin(A& a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A& a, B b) {     if (a < b) a = b;   }   template <class A, class B>   ostream& operator<<(ostream& ost, const pair<A, B>& p) {     ost <<  {  << p.first <<  ,  << p.second <<  } ;     return ost;   }   template <class T>   ostream& operator<<(ostream& ost, const vector<T>& v) {     ost <<  { ;     for (long long i = 0; i < v.size(); i++) {       if (i) ost <<  , ;       ost << v[i];     }     ost <<  } ;     return ost;   }   template <class T>   struct BinaryIndexedTree {     long long n;     vector<T> dat;     BinaryIndexedTree(long long n = 0) : n(n), dat(n + 1) {}     void add(long long k, T x) {       for (k++; k <= n; k += k & -k) dat[k] += x;     }     T sum(long long k) {       T ret{};       for (k++; k; k -= k & -k) ret += dat[k];       return ret;     }   };   long long N;   long long A[222222];   long long K[222222], P[222222];   long long Q;   signed main() {     scanf( %lld , &N);     for (long long i = 0; i < (N); i++) scanf( %lld , &A[i]);     vector<long long> ord(N);     iota((ord).begin(), (ord).end(), 0);     sort((ord).begin(), (ord).end(), [&](long long i, long long j) {       if (A[i] == A[j]) return i < j;       return A[i] > A[j];     });     scanf( %lld , &Q);     vector<vector<long long> > bucket(N);     for (long long i = 0; i < (Q); i++) {       scanf( %lld%lld , &K[i], &P[i]);       K[i]--;       P[i]--;       bucket[K[i]].push_back(i);     }     BinaryIndexedTree<long long> bit(N + 114);     vector<long long> ans(Q);     for (long long i = 0; i < (N); i++) {       bit.add(ord[i], 1);       for (auto j : bucket[i]) {         long long lb = 0, ub = N;         while (ub - lb > 1) {           long long mid = (ub + lb) / 2;           if (bit.sum(mid - 1) <= P[j])             lb = mid;           else             ub = mid;         }         ans[j] = A[lb];       }     }     for (long long i = 0; i < (Q); i++) printf( %lld n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int cnt[2], v[2];   bool f(ll val) {     ll f[] = {val / v[0], val / v[1]};     ll b = v[0] * 1ll * v[1];     ll both = val / b;     ll other = val - f[0] - f[1] + both;     f[0] -= both;     f[1] -= both;     ll tcnt[] = {cnt[0] - f[1], cnt[1] - f[0]};     if (tcnt[0] < 0) tcnt[0] = 0;     if (tcnt[1] < 0) tcnt[1] = 0;     return (tcnt[0] + tcnt[1] <= other);   }   int main() {     cin >> cnt[0] >> cnt[1] >> v[0] >> v[1];     ll l = 0;     ll r = ll(1e18);     while (r - l > 1) {       ll mid = (l + r) >> 1;       if (f(mid)) {         r = mid;       } else {         l = mid;       }     }     cout << r << endl;   }