malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   char str[MAXN][MAXN];   bool used[MAXN][MAXN];   int n, m;   int Move[][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};   int pp[4];   void gao(int id, int dis[][MAXN]) {     queue<pair<int, int> > q;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (str[i][j] == ( 0  + id)) {           dis[i][j] = 0;           q.push(make_pair(i, j));         }       }     }     while (!q.empty()) {       pair<int, int> tmp = q.front();       q.pop();       char ss = str[tmp.first][tmp.second];       if (ss >=  1  && ss <=  3 ) {         if (pp[ss -  0 ] == -1) pp[ss -  0 ] = dis[tmp.first][tmp.second];       }       if (str[tmp.first][tmp.second] != ( 0  + id) &&           str[tmp.first][tmp.second] !=  . )         continue;       for (int i = 0; i < 4; i++) {         int x = tmp.first + Move[i][0];         int y = tmp.second + Move[i][1];         if (x < 0 || x >= n || y < 0 || y >= m) continue;         if (dis[x][y] != -1) continue;         if (str[x][y] ==  # ) continue;         dis[x][y] = dis[tmp.first][tmp.second] + 1;         q.push(make_pair(x, y));       }     }   }   int dp1[MAXN][MAXN], dp2[MAXN][MAXN], dp3[MAXN][MAXN];   void Update(int &a, int b) {     if (b == -1) return;     if (a == -1)       a = b;     else       a = min(a, b);   }   int main() {     while (scanf( %d%d , &n, &m) == 2) {       int ans = -1;       for (int i = 0; i < n; i++) scanf( %s , str[i]);       memset(pp, -1, sizeof(pp));       memset(dp1, -1, sizeof(dp1));       gao(1, dp1);       if (pp[1] != -1 && pp[2] != -1 && pp[3] != -1)         Update(ans, pp[1] + pp[2] + pp[3] - 2);       memset(pp, -1, sizeof(pp));       memset(dp2, -1, sizeof(dp2));       gao(2, dp2);       if (pp[1] != -1 && pp[2] != -1 && pp[3] != -1)         Update(ans, pp[1] + pp[2] + pp[3] - 2);       memset(pp, -1, sizeof(pp));       memset(dp3, -1, sizeof(dp3));       gao(3, dp3);       if (pp[1] != -1 && pp[2] != -1 && pp[3] != -1)         Update(ans, pp[1] + pp[2] + pp[3] - 2);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           if (dp1[i][j] == -1) continue;           if (dp2[i][j] == -1) continue;           if (dp3[i][j] == -1) continue;           Update(ans, max(0, dp1[i][j] - 1) + max(0, dp2[i][j] - 1) +                           max(0, dp3[i][j] - 1) + (str[i][j] ==  . ));         }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     vector<long long> mult(32, 1);     for (int i = 0; i < 32; i++) mult[i] = (1 << i) + 1;     int t;     cin >> t;     while (t--) {       long long d, m, final = 1;       cin >> d >> m;       d++;       int x = logb(d);       for (int i = 0; i < x; i++) {         final *= (mult[i]) % m;         final %= m;       }       final *= (d - ((1 << (x))) + 1) % m;       cout << (final % m - 1 + m) % m << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int T[1000010][30], cnt = 0, fa[1000010];   char s[400010];   struct Q {     int id, x;   };   int A[400010], val[400010];   vector<Q> g[1000010];   vector<int> gg[1000010];   queue<int> q;   void insert(int id) {     int f = 0, i, v;     for (i = 0; s[i]; i++) {       v = s[i] -  a ;       if (T[f][v] == 0) T[f][v] = ++cnt;       f = T[f][v];     }     A[id] = f;   }   void build() {     int i, u, v, p;     for (i = 0; i < 27; i++)       if (T[0][i]) q.push(T[0][i]);     for (; q.size(); q.pop()) {       u = q.front();       gg[fa[u]].push_back(u);       for (i = 0; i < 27; i++) {         v = T[u][i];         if (v) {           p = fa[u];           while (p && T[p][i] == 0) p = fa[p];           fa[v] = T[p][i];           q.push(v);         }       }     }   }   int in[1000010], out[1000010], dfn = 0;   void dfs(int u) {     int i, v;     in[u] = ++dfn;     for (i = 0; i < gg[u].size(); i++) {       v = gg[u][i];       dfs(v);     }     out[u] = dfn;   }   int sum[1000100], ans[400010];   int lb(int x) { return x & -x; }   void add(int x, int v) {     for (; x <= 1e6; x += lb(x)) sum[x] += v;   }   int qsum(int x) {     int k = 0;     for (; x; x -= lb(x)) k += sum[x];     return k;   }   void dfs1(int u) {     int i, v;     add(in[u], 1);     Q x;     for (i = 0; i < g[u].size(); i++) {       x = g[u][i];       ans[x.id] = qsum(out[x.x]) - qsum(in[x.x] - 1);     }     for (i = 0; i < 27; i++)       if (T[u][i]) dfs1(T[u][i]);     add(in[u], -1);   }   int main() {     int i, n, k, v, u, m, j;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &k);       if (k == 1) {         scanf( %s , s);         v = s[0] -  a ;         if (T[0][v] == 0) T[0][v] = ++cnt;         val[i] = T[0][v];       } else {         scanf( %d%s , &k, s);         v = s[0] -  a ;         u = val[k];         if (T[u][v] == 0) T[u][v] = ++cnt;         val[i] = T[u][v];       }     }     scanf( %d , &m);     for (i = 1; i <= m; i++) {       scanf( %d%s , &k, s);       insert(i);       g[val[k]].push_back(Q({i, A[i]}));     }     build();     dfs(0);     dfs1(0);     for (i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sum;   int cV = 0;   void add(string n, int c) {     if (n.size() == 1) {       cV = c;       return;     }     sum = 0;     for (char e : n) {       int a = e -  0 ;       sum += a;     }     c++;     add(to_string(sum), c);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string n;     cin >> n;     add(n, 0);     cout << cV <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& v) {     os <<  (  << v.first <<     << v.second <<  ) ;     return os;   }   template <typename T, typename U = typename T::value_type,             typename = typename enable_if<!is_same<T, string>::value>::type>   ostream& operator<<(ostream& os, const T& v) {     os <<  [ ;     for (const auto& it : v) os << it <<    ;     if (!v.empty()) os <<   b ;     os <<  ] ;     return os;   }   int64_t binom2(int64_t N) {     if (N < 2) return 0;     return (N * (N - 1)) / 2;   }   struct Counter {     struct Node {       vector<int> y;       unique_ptr<Node> left, right;       Node(const vector<int>& p, int node_left, int node_right)           : y(p.begin() + node_left, p.begin() + node_right) {         sort((y).begin(), (y).end());         if (y.size() >= 2) {           int node_middle = (node_left + node_right) / 2;           left.reset(new Node(p, node_left, node_middle));           right.reset(new Node(p, node_middle, node_right));         }       }     };     unique_ptr<Node> root;     void init(const vector<int>& p) { root.reset(new Node(p, 0, p.size())); }     int go_count(const Node* node, int node_left, int node_right, int l, int r,                  int d, int u) {       if (node_left >= r || node_right <= l) return 0;       if (l <= node_left && node_right <= r)         return upper_bound((node->y).begin(), (node->y).end(), u) -                lower_bound((node->y).begin(), (node->y).end(), d);       int node_middle = (node_left + node_right) / 2;       return go_count(node->left.get(), node_left, node_middle, l, r, d, u) +              go_count(node->right.get(), node_middle, node_right, l, r, d, u);     }     int count(int l, int r, int d, int u) {       return go_count(root.get(), 0, root->y.size(), l, r + 1, d, u);     }   };   int N, Q;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cin >> N >> Q;     vector<int> p(N);     for (int i = 0; i < (N); i++) {       cin >> p[i];       p[i]--;     }     Counter counter;     counter.init(p);     for (int i = 0; i < (Q); i++) {       int l, d, r, u;       cin >> l >> d >> r >> u;       l--, d--, r--, u--;       int64_t ans = binom2(N) - binom2(l) - binom2(N - r - 1);       ans -= binom2(counter.count(0, N - 1, u + 1, N - 1));       ans -= binom2(counter.count(0, N - 1, 0, d - 1));       ans += binom2(counter.count(0, l - 1, 0, d - 1));       ans += binom2(counter.count(0, l - 1, u + 1, N - 1));       ans += binom2(counter.count(r + 1, N - 1, 0, d - 1));       ans += binom2(counter.count(r + 1, N - 1, u + 1, N - 1));       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int INF = 2147483647;   int inf = -2147483648;   const double PI = acos(-1.0);   const double pi = 2 * asin(1.0);   int vis[1000009];   int vi[1000009];   int main() {     ios::sync_with_stdio(false);     int a, b, c, d;     cin >> a >> b >> c >> d;     for (int i = 0; i <= 100; i++) {       vis[b + a * i] = 1;     }     for (int i = 0; i <= 100; i++) {       vi[d + c * i] = 1;     }     for (int i = 0; i < 1000009; i++) {       if (vis[i] == 1 && vi[i] == 1) {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   clock_t start;   void Time(bool timeIt) {     if (!timeIt) return;     clock_t end = clock();     double elapsed_time =         ((long double)end - (long double)start) / (long double)CLOCKS_PER_SEC;     fprintf(stderr,  Time elapsed = %0.4lf n , elapsed_time);   }   const int SIZE = 200010;   const int ALPHABET = 26;   char a[SIZE], b[SIZE];   vector<pair<long long, long long> > ps[ALPHABET][2];   int main() {     start = clock();     int n;     scanf( %d %s %s , &n, a, b);     long long numerator = 0, denominator = 0;     for (long long i = 1; i <= n; ++i) {       denominator += 1ll * (n - i + 1) * (n - i + 1);     }     for (int i = 0; i < n; ++i) {       int ch = a[i] -  A ;       if (ps[ch][0].empty()) {         ps[ch][0].push_back(make_pair(i + 1, i));         ps[ch][1].push_back(make_pair(n - i, i));       } else {         ps[ch][0].push_back(make_pair(ps[ch][0].back().first + i + 1, i));         ps[ch][1].push_back(make_pair(ps[ch][1].back().first + n - i, i));       }     }     long double ans = 0;     for (int i = 0; i < n; ++i) {       int ch = b[i] -  A ;       int e = ps[ch][0].size(), s = -1;       while (e - s > 1) {         int m = (e + s) >> 1;         if (ps[ch][0][m].second <= i)           s = m;         else           e = m;       }       if (s != -1)         ans += (long double)(1ll * ps[ch][0][s].first * (n - i)) /                (long double)denominator;       e = ps[ch][1].size();       s = -1;       while (e - s > 1) {         int m = (e + s) >> 1;         if (ps[ch][1][m].second > i)           e = m;         else           s = m;       }       if (e != ps[ch][1].size()) {         long long sum =             (ps[ch][1].back().first - (s != -1 ? ps[ch][1][s].first : 0));         ans += (long double)(1ll * sum * (i + 1)) / (long double)denominator;       }     }     printf( %0.10Lf n , ans);     Time(true);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target( avx,avx2 )   using namespace std;   long long mod = 1e9 + 7;   const long long inf = 1e9;   int main() {     cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);     int n, l, x, y;     cin >> n >> l >> x >> y;     vector<int> a(n);     set<int> ax, ay;     map<int, int> have;     bool havex = 0, havey = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       have[a[i]] = 1;     }     for (int i = 0; i < n; ++i) {       if (a[i] + x < l && !have[a[i] + x]) ax.insert(a[i] + x);       if (a[i] + y < l && !have[a[i] + y]) ay.insert(a[i] + y);       if (a[i] - x > 0 && !have[a[i] - x]) ax.insert(a[i] - x);       if (a[i] - y > 0 && !have[a[i] - y]) ay.insert(a[i] - y);     }     for (int i = 0; i < n; ++i) {       if (have[a[i] - x] || have[a[i] + x]) havex = 1;       if (have[a[i] - y] || have[a[i] + y]) havey = 1;     }     vector<int> ans;     if (havex && havey) {       cout << 0;       exit(0);     }     if (havex) {       cout <<  1 n  << (*ay.begin());       exit(0);     }     if (havey) {       cout <<  1 n  << (*ax.begin());       exit(0);     }     for (int val : ax) {       if (ay.count(val)) {         cout <<  1 n  << val;         exit(0);       }     }     cout <<  2 n  << (*ax.begin()) <<     << (*ay.begin());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int main() {     int n;     scanf( %d , &n);     long long sum = 0;     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       while (1) {         if (mp[a] == 0 || a == 0) {           mp[a] = 1;           sum += (long long)a;           break;         } else           a--;       }     }     printf( %I64d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int p[100010];   bool used[100010];   int main() {     scanf( %d , &n);     memset(p, 0, sizeof(p));     memset(used, false, sizeof(used));     if (n == 1) {       printf( 1 n );       return 0;     }     if (n % 2 == 0) {       if (n % 4 != 0) {         printf( -1 n );         return 0;       }     } else {       if ((n - 1) % 4 != 0) {         printf( -1 n );         return 0;       }     }     if (n % 2 != 0) {       p[n / 2 + 1] = n / 2 + 1;       used[n / 2 + 1] = true;     }     for (int i = 1; i <= n / 2; i++) {       if (!p[i]) {         int num = 1;         while (used[num] || num == i) num++;         p[i] = num;         used[num] = true;         p[num] = n + 1 - i;         used[n + 1 - i] = true;         p[n + 1 - i] = n + 1 - num;         used[n + 1 - num] = true;         p[n + 1 - num] = i;         used[i] = true;       }     }     for (int i = 1; i <= n; i++) printf( %d  , p[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v;     for (int i = 1; i <= 20; ++i) {       int first = ((1 << i) - 1) * (1 << (i - 1));       if (first > 1e5) break;       v.push_back(first);     }     for (int i = v.size() - 1; i >= 0; --i) {       if (n % v[i] == 0) return cout << v[i], 0;     }     return 0;   }
#include <bits/stdc++.h>   int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};   int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};   using namespace std;   long long power(long long a, long long p, long long M) {     long long r = 1;     a = a % M;     while (p > 0) {       if (p % 2) r = (r * a) % M;       a = (a * a) % M;       p /= 2;     }     return r;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int n;   long long a[200000];   vector<long long> v[200000];   void solve() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     ;     for (int i = 0; i < n; i++) {       v[i].push_back(0);     }     for (int i = 0; i < n; i++) {       long long l = 0, r = n - 1;       while (l <= r) {         long long mid = (l + r) / 2;         if (v[mid][v[mid].size() - 1] < a[i]) {           r = mid - 1;         } else {           l = mid + 1;         }       }       v[l].push_back(a[i]);     }     for (int i = 0; i < n; i++) {       if (v[i].size() > 1) {         for (int j = 1; j < v[i].size(); j++) {           printf( %lld  , v[i][j]);         }         printf(  n );       } else {         break;       }     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[51][51], ans[51];   bool check(int j, int x) {     for (int i = 1; i <= n; i++)       if (a[j][i] > x || a[i][j] > x) return false;     ans[j] = x;     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]);     for (int i = 1; i <= n; i++) {       int j = 1;       while (ans[j] || !check(j, i)) j++;     }     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     if (s.length() < 26) {       cout << -1 << endl;       return 0;     }     int j = -1;     for (int i = 0; i < s.length(); i++)       if (s[i] ==  a ) {         j = i + 1;         break;       }     if (j == -1) {       cout << -1 << endl;       return 0;     }     for (char c =  b ; c <=  z ; c++) {       bool f = 0;       for (int i = j; i < s.length(); i++) {         if (s[i] <= (char)(c - 1)) {           s[i] = c, j = i + 1, f = 1;           break;         }         if (s[i] == (char)(c)) {           j = i + 1, f = 1;           break;         }       }       if (f == 0) {         cout << -1 << endl;         return 0;       }     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n;   long long a[maxn], l[maxn], r[maxn], lans[maxn], rans[maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     for (int i = 1; i <= n; i++) {       l[i] = max(a[i], l[i - 1] + 1);       lans[i] = l[i] - a[i] + lans[i - 1];     }     for (int i = n; i >= 0; i--) {       r[i] = max(a[i], r[i + 1] + 1);       rans[i] = r[i] - a[i] + rans[i + 1];     }     long long ans = 1e18;     for (int i = 1; i <= n; i++)       ans =           min(ans, lans[i - 1] + rans[i + 1] + max(l[i], max(r[i], a[i])) - a[i]);     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005, INF = 2e9;   int n, m, k, p[N][N], rnk[N][N], le[N][N], ri[N][N];   bool used[N][N], iswap;   pair<int, pair<int, int> > ans;   int dsu_get(int x, int y) {     return p[x][y] == y ? y : p[x][y] = dsu_get(x, p[x][y]);   }   inline void dsu_unite(int x, int y1, int y2) {     int px = dsu_get(x, y1), py = dsu_get(x, y2);     if (px != py) {       if (rnk[x][px] < rnk[x][py]) {         swap(px, py);       }       if (rnk[x][px] == rnk[x][py]) {         rnk[x][px]++;       }       p[x][py] = px;       le[x][px] = min(le[x][px], le[x][py]);       ri[x][px] = max(ri[x][px], ri[x][py]);     }   }   inline void upd(pair<int, pair<int, int> > val) {     if (iswap) {       if (val.first < ans.first) {         ans = val;       } else if (val.first == ans.first) {         auto it1 = ans.second, it2 = val.second;         swap(it1.first, it1.second);         swap(it2.first, it2.second);         if (it1 > it2) {           ans = val;         }       }     } else {       ans = min(ans, val);     }   }   inline pair<int, int> getans(int x, int y) {     ans = make_pair(INF, make_pair(-1, -1));     for (int i = 0; i <= ans.first; i++) {       if (x - i >= 1) {         int py = dsu_get(x - i, y);         int ll = le[x - i][py], rr = ri[x - i][py];         if (used[x - i][ll]) {           ll--;         }         if (used[x - i][rr]) {           rr++;         }         if (ll >= 1) {           upd(make_pair(i + y - ll, make_pair(x - i, ll)));         }         if (rr <= m) {           upd(make_pair(i + rr - y, make_pair(x - i, rr)));         }       }       if (x + i <= n) {         int py = dsu_get(x + i, y);         int ll = le[x + i][py], rr = ri[x + i][py];         if (used[x + i][ll]) {           ll--;         }         if (used[x + i][rr]) {           rr++;         }         if (ll >= 1) {           upd(make_pair(i + y - ll, make_pair(x + i, ll)));         }         if (rr <= m) {           upd(make_pair(i + rr - y, make_pair(x + i, rr)));         }       }     }     return ans.second;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     if (n > m) {       iswap = true;       swap(n, m);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         le[i][j] = ri[i][j] = p[i][j] = j;       }     }     while (k--) {       int x, y;       cin >> x >> y;       if (iswap) {         swap(x, y);       }       auto it = getans(x, y);       used[it.first][it.second] = true;       if (it.second - 1 >= 1 && used[it.first][it.second - 1]) {         dsu_unite(it.first, it.second - 1, it.second);       }       if (it.second + 1 <= m && used[it.first][it.second + 1]) {         dsu_unite(it.first, it.second, it.second + 1);       }       if (iswap) {         swap(it.first, it.second);       }       cout << it.first <<     << it.second <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int P = 998244353;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> a(n), c(m, -1), d(m), bb(m);     map<int, int> b;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int j = 0; j < m; j++) {       int q;       cin >> q;       b.insert(make_pair(q, j));       bb[j] = q;     }     for (int k = 0; k < n; k++) {       if (b.find(a[k]) != b.end()) {         c[b.find(a[k])->second] = k;       }     }     if (c[0] == -1) {       cout << 0;       return 0;     }     for (int l = 1; l < m; l++) {       if ((c[l] < c[l - 1]) || (c[l - 1] == -1)) {         cout << 0;         return 0;       }     }     int s = 0, t = 0;     d[0] = c[0];     while (s <= c[t]) {       if (t >= 1) {         if (a[s] < bb[t - 1]) {           cout << 0;           return 0;         }       }       if (a[s] < bb[t]) d[t] = s;       if (s == c[t]) {         t++;         if (t >= m) break;         d[t] = c[t - 1];       }       s++;     }     if (d[0] < c[0]) {       cout << 0;       return 0;     }     for (int e = c[m - 1]; e < n; e++) {       if (a[e] < bb[m - 1]) {         cout << 0;         return 0;       };     }     if (m == 1) {       cout << 1;       return 0;     }     long long int sum = 1;     for (int w = 1; w < m; w++) {       sum = (sum * (c[w] - d[w])) % P;     }     cout << sum;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::deque;   using std::endl;   using std::map;   using std::max;   using std::min;   using std::multiset;   using std::pair;   using std::queue;   using std::set;   using std::sort;   using std::stack;   using std::string;   using std::vector;   int n, k, s, t;   int c[200005] = {       0,   };   int v[200005] = {       0,   };   int g[200005] = {       0,   };   bool isGood(int middle) {     int time = 0;     for (int i = 1; i <= k + 1; i++) {       int len = g[i] - g[i - 1];       if (len > middle) {         return false;       }       if (middle >= len * 2) {         time += len;       } else {         time += (len * 2 - middle) * 2 + (middle - len);       }     }     if (time <= t) return true;     return false;   }   int main() {     cin >> n >> k >> s >> t;     for (int i = 0; i < n; i++) {       scanf( %d%d , c + i, v + i);     }     g[0] = 0;     g[k + 1] = s;     for (int i = 1; i <= k; i++) {       scanf( %d , g + i);     }     sort(g, g + k + 2);     const int up = 2123456789;     int badBak = 0;     int goodBak = up;     while (badBak + 1 != goodBak) {       int middle = (int)((1LL * badBak + goodBak) / 2);       if (isGood(middle)) {         goodBak = middle;       } else {         badBak = middle;       }     }     if (goodBak == up) {       cout << -1;       return 0;     }     int cheap = up;     for (int i = 0; i < n; i++) {       if (v[i] >= goodBak && c[i] < cheap) {         cheap = c[i];       }     }     if (cheap == up) {       cout << -1;       return 0;     }     cout << cheap;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, p, q, a;     cin >> t;     while (t--) {       cin >> n >> p >> q;       vector<long long int> player1, player2;       for (unsigned long long i = 0; i < p; i++) {         cin >> a;         player1.push_back(a);       }       for (unsigned long long i = 0; i < q; i++) {         cin >> a;         player2.push_back(a);       }       sort(player1.begin(), player1.end(), greater<long long int>());       sort(player2.begin(), player2.end(), greater<long long int>());       if (player1[0] > player2[0])         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }