malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long mo(long long a) { return a % (long long)(1e9 + 7); }   long long po(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y >>= 1;       x = (x * x) % p;     }     return res % p;   }   vector<vector<pair<long long, long long>>> g;   vector<long long> vis, col;   vector<vector<long long>> ty;   void dfs(long long par, long long anc = -1, long long type = -1) {     if (anc == -1) {       col[par] = 0;       ty[col[par]].push_back(par);     } else {       if (type) {         col[par] = !col[anc];         ty[col[par]].push_back(par);       } else {         col[par] = col[anc];         ty[col[par]].push_back(par);       }     }     vis[par] = 1;     for (pair<long long, long long> e : g[par]) {       if (!vis[e.first]) {         dfs(e.first, par, e.second);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<vector<long long>> r(n, vector<long long>(2, -1)),           c(n, vector<long long>(2, -1));       for (long long i = 0; i < 2; i++) {         for (long long j = 0; j < n; j++) {           long long x;           cin >> x;           x--;           if (r[x][0] == -1)             r[x][0] = i;           else             r[x][1] = i;           if (c[x][0] == -1)             c[x][0] = j;           else             c[x][1] = j;         }       }       long long pos = 1;       for (long long i = 0; i < n; i++) {         if (r[i][0] == -1 || r[i][1] == -1) pos = 0;       }       if (!pos) {         cout << -1 <<   n ;         continue;       }       g.assign(n, {});       vis.assign(n, 0);       col.assign(n, -1);       ty.assign(2, {});       for (long long i = 0; i < n; i++) {         if (r[i][0] == r[i][1] && c[i][0] != c[i][1]) {           g[c[i][0]].push_back({c[i][1], 1});           g[c[i][1]].push_back({c[i][0], 1});         }         if (r[i][0] != r[i][1] && c[i][0] != c[i][1]) {           g[c[i][1]].push_back({c[i][0], 0});           g[c[i][0]].push_back({c[i][1], 0});         }       }       vector<long long> ans;       for (long long i = 0; i < n; i++) {         if (!vis[i]) {           ty[0].clear();           ty[1].clear();           dfs(i);           if (ty[0].size() > ty[1].size()) swap(ty[0], ty[1]);           for (long long e : ty[0]) ans.push_back(e);         }       }       cout << ans.size() <<   n ;       for (long long e : ans) cout << e + 1 <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a, b, max_dollars, min_tokens, n_tokens;     string raw_input;     cin >> n >> a >> b;     vector<string> tokens(n);     for (int i = 0; i < n; i++) cin >> tokens[i];     for (int i = 0; i < n; i++) {       n_tokens = stoll(tokens[i]);       max_dollars = n_tokens * a / b;       if (stoll(tokens[i]) * a % b != 0) {         min_tokens = ceil((max_dollars * 1.0) * b / a);         cout << n_tokens - min_tokens <<    ;       } else {         cout << 0 <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t, x, y, a, b;     cin >> t;     while (t--) {       cin >> x >> y >> a >> b;       if (2 * a < b)         cout << a * (x + y) <<   n ;       else         cout << b * min(x, y) + a * abs(x - y) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tc;     cin >> tc;     while (tc--) {       int n;       cin >> n;       string s;       cin >> s;       if (n == 2) {         if (s[0] >= s[1]) {           cout <<  NO                 <<   n ;         } else {           cout <<  YES                 <<   n ;           cout <<  2                 <<   n ;           cout << s[0] <<     << s[1] <<   n ;         }       } else {         cout <<  YES               <<   n ;         cout <<  2               <<   n ;         cout << s[0] <<    ;         for (int i = 1; i < n; i++) {           cout << s[i];         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int maxn = 1000000 + 5;   const double PI = acos(-1.0);   const double E = 2.718281828459;   const double eps = 1e-7;   int T, n, num[100005];   int main() {     long k, n = 19, x = 0, m;     scanf( %ld , &k);     while (k - 1 > 0) {       x = 0;       n++;       m = n;       while (m > 0) {         x += m % 10;         m /= 10;       }       if (x == 10) {         k--;       }     }     printf( %ld n , n);   }
#include <bits/stdc++.h>   using namespace std;   vector<int> solve(int n) {     vector<int> v(n, 1);     if (n == 1) return v;     if (n == 2) {       v[0] = 3, v[1] = 4;       return v;     }     int k = n - 1;     if (k & 1) {       int p = k >> 1;       v[n - 1] = p;     } else {       k = k - 1 + 4;       int p = k >> 1;       v[n - 2] = 2, v[n - 1] = p;     }     return v;   }   int main() {     int n, m;     while (cin >> n >> m) {       vector<int> v1 = solve(n), v2 = solve(m);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           printf( %d%c , v1[i] * v2[j], j + 1 == m ? 10 : 32);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n, d, x, y;     vector<pair<int, int> > v;     cin >> n >> d >> a >> b;     for (int i = 0; i < n; i++) {       cin >> x >> y;       v.push_back({x * a + y * b, i});     }     sort(v.begin(), v.end());     long long sum = 0, in = 0;     for (int i = 0; i < n; i++) {       if (sum + v[i].first > d) break;       sum += v[i].first;       in++;     }     cout << in << endl;     for (int i = 0; i < in - 1; i++) cout << v[i].second + 1 <<    ;     if (in > 0) cout << v[in - 1].second + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int hy, ay, dy;   int hm, am, dm;   int h, a, d;   bool firstok = true;   bool ok(int H, int A, int D) {     int d1 = max(0, A - dm);     int d2 = max(0, am - D);     if (d1 == 0 && d2 == 0) return false;     if (d2 == 0) return true;     if (d1 == 0) return false;     int r1 = (int)ceil(double(hm) / d1);     if (H % d2 == 0 && r1 < H / d2)       return true;     else if (H % d2 != 0 && r1 <= H / d2)       return true;     return false;   }   int main() {     cin >> hy >> ay >> dy;     cin >> hm >> am >> dm;     cin >> h >> a >> d;     int minm = 100000000;     for (__typeof(200) i = 0; i < (200); ++i)       for (__typeof(200) j = 0; j < (200); ++j) {         int A = ay + i;         int D = dy + j;         int k1 = max(0, A - dm);         int k2 = max(0, am - D);         if (k1 == 0) continue;         if (k2 == 0) {           minm = min(minm, i * a + j * d);           continue;         }         int t = (int)ceil((double)hm / k1);         int k = t * k2 - hy + 1;         k = max(0, k);         minm = min(minm, i * a + j * d + k * h);       }     cout << minm << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n * 2], b[n * 2];     for (int i = 0; i < (n); ++i) {       cin >> a[i] >> b[i];       a[i + n] = a[i];       b[i + n] = b[i];     }     int flag = 1;     if (n % 2 == 1) flag = 0;     for (int i = 0; i < (n); ++i) {       int x = a[i + 1] - a[i];       int y = b[i + 1] - b[i];       if (a[i + n / 2 + 1] - a[i + n / 2] != -x) flag = 0;       if (b[i + n / 2 + 1] - b[i + n / 2] != -y) flag = 0;     }     if (flag) {       puts( YES );     } else {       puts( NO );     };     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n;     cin >> n;     if (n == 0)       cout << 1 << endl;     else if (n % 4 == 1)       cout << 8 << endl;     else if (n % 4 == 2)       cout << 4 << endl;     else if (n % 4 == 3)       cout << 2 << endl;     else       cout << 6 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int LIS(vector<int> A) {     int N = A.size(), i;     multiset<int> s;     multiset<int>::iterator k;     for (i = 0; i < N; i++) {       s.insert(A[i]);       if (1) {         k = s.find(A[i]);         k++;         if (k != s.end()) s.erase(k);       }     }     return s.size();   }   int main() {     int n;     cin >> n;     string s;     cin >> s;     for (int i = 1; i < n; i++) {       for (int j = 0; j + 4 * i < n; j++) {         if (s[j] !=  * ) continue;         if (s[j + i] == s[j] && s[j + 2 * i] == s[j] && s[j + 3 * i] == s[j] &&             s[j + 4 * i] == s[j]) {           cout <<  yes ;           return 0;         }       }     }     cout <<  no ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int current = 1, maxtotal = 0;     for (int i = 0; i < n; i++) {       current = 1;       for (int j = i; j < n - 1 && a[j] >= a[j + 1]; j++, current++)         ;       for (int j = i; j > 0 && a[j] >= a[j - 1]; j--, current++)         ;       if (current > maxtotal) {         maxtotal = current;       }     }     cout << maxtotal;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxx = 1e5 + 20;   long long a[maxx];   int main() {     int n, i;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int r;     while (a[0] % 2 == 0) a[0] /= 2;     while (a[0] % 3 == 0) a[0] /= 3;     r = a[0];     for (i = 1; i < n; i++) {       while (a[i] % 2 == 0) a[i] /= 2;       while (a[i] % 3 == 0) a[i] /= 3;       if (a[i] != r) {         cout <<  No ;         return 0;       }     }     cout <<  Yes ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct CC {     long long x1, x2, y1, y2;   };   CC jiao(CC a, CC b) {     CC c1;     c1.x1 = max(a.x1, b.x1);     c1.y1 = max(a.y1, b.y1);     c1.x2 = min(a.x2, b.x2);     c1.y2 = min(a.y2, b.y2);     return c1;   }   int main() {     CC w, b1, b2;     cin >> w.x1 >> w.y1 >> w.x2 >> w.y2 >> b1.x1 >> b1.y1 >> b1.x2 >> b1.y2 >>         b2.x1 >> b2.y1 >> b2.x2 >> b2.y2;     CC j1 = jiao(w, b1);     CC j2 = jiao(w, b2);     CC j3 = jiao(j1, j2);     long long s, s1, s2, s3;     s = (w.x2 - w.x1) * (w.y2 - w.y1);     if (j1.x1 > j1.x2 || j1.y1 > j1.y2)       s1 = 0;     else       s1 = (j1.x2 - j1.x1) * (j1.y2 - j1.y1);     if (j2.x1 > j2.x2 || j2.y1 > j2.y2)       s2 = 0;     else       s2 = (j2.x2 - j2.x1) * (j2.y2 - j2.y1);     if (j3.x1 > j3.x2 || j3.y1 > j3.y2)       s3 = 0;     else       s3 = (j3.x2 - j3.x1) * (j3.y2 - j3.y1);     if (s1 + s2 - s3 == s)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[22], b[22], d[22][44], mat[44][44], res[44][44], t[44][44];   void calc(int x[44][44], int y[44][44], int z[44][44]) {     for (int i = 0; i <= 2 * n; ++i)       for (int j = 0; j <= 2 * n; ++j) {         t[i][j] = (int)(2e9);         for (int k = 0; k <= 2 * n; ++k) {           if (x[i][k] != (int)(2e9) && y[k][j] != (int)(2e9))             t[i][j] = min(t[i][j], x[i][k] + y[k][j]);         }       }     for (int i = 0; i <= 2 * n; ++i)       for (int j = 0; j <= 2 * n; ++j) {         z[i][j] = t[i][j];       }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     for (int start = 0; start <= 2 * n; ++start) {       for (int i = 0; i <= n; ++i)         for (int j = 0; j <= 2 * n; ++j) d[i][j] = (int)(2e9);       d[0][start] = 0;       for (int i = 0; i < n; ++i)         for (int j = 0; j <= 2 * n; ++j) {           if (d[i][j] != (int)(2e9)) {             if (j > 0) d[i + 1][j - 1] = min(d[i + 1][j - 1], d[i][j] + b[i]);             if (j < 2 * n) d[i + 1][j + 1] = min(d[i + 1][j + 1], d[i][j] + a[i]);           }         }       for (int j = 0; j <= 2 * n; ++j) mat[start][j] = d[n][j];     }     for (int i = 0; i <= 2 * n; ++i)       for (int j = 0; j <= 2 * n; ++j) res[i][j] = (int)(2e9);     res[0][0] = 0;     while (m) {       if (m & 1) calc(res, mat, res);       calc(mat, mat, mat);       m >>= 1;     }     cout << res[0][0];   }
#include <bits/stdc++.h>   const int Inf = 2e9;   long long LINF = (long long)4e18;   using namespace std;   int r1, r2, c1, c2, d1, d2;   bool ok(int i, int j, int k, int l) {     if (i + j != r1) return false;     if (k + l != r2) return false;     if (i + k != c1) return false;     if (j + l != c2) return false;     if (i + l != d1) return false;     if (j + k != d2) return false;     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;     for (int i = 1; i <= 9; i++) {       for (int j = 1; j <= 9; j++) {         for (int k = 1; k <= 9; k++) {           for (int l = 1; l <= 9; l++) {             if (i == j) continue;             if (i == k) continue;             if (i == l) continue;             if (j == k) continue;             if (j == l) continue;             if (k == l) continue;             if (!ok(i, j, k, l)) continue;             cout << i <<     << j <<   n ;             cout << k <<     << l <<   n ;             return 0;           }         }       }     }     cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 22;   int n;   int col[Maxn];   int main() {     scanf( %d , &n);     int cur = 0;     for (int a = 0; cur < n; a++) {       bool good = true;       for (int i = 0; i < cur && good; i++)         for (int j = i + 1; j < cur && good; j++)           for (int l = 0; l < cur && good; l++)             if (i != l && j != l) good = a != col[i] + col[j] - col[l];       if (good) col[cur++] = a;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         printf( %d%c , i == j ? 0 : col[i] + col[j], j + 1 < n ?     :   n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t, n, k, z, x, s, a[31], v[31][101], c[31];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     cin >> t;     for (int zxc = 1; zxc <= t; zxc++) {       cin >> n >> k;       for (int i = 1; i <= 30; i++)         for (int j = 1; j <= 100; j++) v[i][j] = 0;       for (int i = 1; i <= n; i++) cin >> a[i];       for (int i = 1; i <= n; i++) {         long long z = a[i];         long long x = 0;         while (z != 0) {           x++;           v[i][x] = z % k;           z /= k;         }       }       int ff = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= 100; j++) {           if (v[i][j] > 1) {             ff = 1;             break;           }         }         if (ff == 1) break;       }       if (ff == 1)         cout <<  NO               <<   n ;       else {         for (int j = 1; j <= 100; j++) {           long long x = 0;           for (int i = 1; i <= n; i++)             if (v[i][j] == 1) x++;           if (x > 1) {             ff = 1;             break;           }         }         if (ff == 1)           cout <<  NO                 <<   n ;         else           cout <<  YES                 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int get(int xt) {     int ans = 0;     for (int i = 0; i < 8; i++) {       ans *= 2;       ans += xt % 2;       xt /= 2;     }     return ans;   }   int main() {     char a[110] =   ;     gets(a);     int len = strlen(a);     int xt = 0;     for (int i = 0; i < len; i++) {       int tmp = a[i];       tmp = get(tmp);       if (i != len)         cout << (xt - tmp + 256) % 256 << endl;       else         cout << (xt - tmp + 256) % 256;       xt = tmp;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 7;   int dp[N][N];   int cnt[N * N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a[n];     memset(dp, 0, sizeof(dp));     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < n; i++) cin >> a[i];     int ini = 0;     for (int i = 1; i < n; i++) {       for (int j = 0; j < n; j++) dp[i][j] = dp[i - 1][j];       for (int j = 0; j < n; j++) {         if (a[i] > j) dp[i][j]++;       }       for (int j = 0; j < i; j++) {         if (a[j] > a[i]) ini++;       }     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         int val = dp[i][a[i]] + dp[j][a[j]] - dp[i][a[j]] - dp[j][a[i]];         val = ini - 2 * val - 1;         cnt[val]++;       }     }     for (int i = 0; i < N * N; i++) {       if (cnt[i]) {         cout << i <<     << cnt[i] << endl;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int query(vector<int>& v) {     cout <<  ?  ;     for (auto& x : v) {       cout << x <<    ;     }     cout << endl;     int a;     cin >> a;     return a;   }   void solve(int n) {     int x = 1;     vector<int> v(n, 1);     for (int i = n; i >= 2; i--) {       for (int j = 0; j < n - 1; j++) {         v[j] = i;       }       int a = query(v);       if (a == 0) continue;       x = i;       break;     }     vector<int> ans(n, -1);     ans[n - 1] = x;     for (int i = 0; i < n; i++) {       v[i] = x;     }     for (int i = 1; i <= n; i++) {       if (i == x) continue;       v[n - 1] = i;       int index = query(v);       ans[index - 1] = i;     }     cout <<  !  ;     for (auto& y : ans) {       cout << y <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       int n;       cin >> n;       solve(n);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   int n, m, maxw, tot, w[maxn], b[maxn], fa[maxn], sumw[maxn], sumb[maxn],       dp[maxn << 1][maxn], f[maxn];   vector<int> child[maxn];   vector<pair<int, int> > vec;   unordered_set<int> ancestor;   void init() {     for (int i = 1; i <= n; i++) {       fa[i] = i;       sumw[i] = w[i];       sumb[i] = b[i];     }   }   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   void unite(int x, int y) {     x = find(x), y = find(y);     if (x == y) return;     fa[x] = y;     sumw[y] += sumw[x];     sumb[y] += sumb[x];   }   int main() {     scanf( %d %d %d , &n, &m, &maxw);     for (int i = 1; i <= n; i++) {       scanf( %d , &w[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);     }     init();     while (m--) {       int x, y;       scanf( %d %d , &x, &y);       unite(x, y);     }     for (int i = 1; i <= n; i++) {       child[find(i)].push_back(i);       ancestor.insert(find(i));     }     for (int x : ancestor) {       int last = tot;       for (int y : child[x]) {         tot++;         for (int z = 0; z <= maxw; z++) {           dp[tot][z] = f[z];           if (z >= w[y]) {             dp[tot][z] = max(dp[tot][z], f[z - w[y]] + b[y]);           }         }       }       tot++;       for (int y = 0; y <= maxw; y++) {         dp[tot][y] = f[y];         if (y >= sumw[x]) {           dp[tot][y] = max(dp[tot][y], f[y - sumw[x]] + sumb[x]);         }       }       for (int y = last + 1; y <= tot; y++) {         for (int z = 0; z <= maxw; z++) {           f[z] = max(f[z], dp[y][z]);         }       }     }     printf( %d n , *max_element(f, f + maxw + 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long a[N], n;   int to_sorted[N];   int to_nature[N];   bool done(int i, int d) {     bool lef = (i == 0 || a[i - 1] < a[i] - d);     bool rig = (i == n - 1 || a[i] + d < a[i + 1]);     return lef && rig;   }   int front(int, int);   int back(int, int);   int front(int i, int d) {     if (done(i, d)) {       return i;     }     int id = upper_bound(a, a + n, a[i] + d) - a - 1;     long long rot = 2 * abs(a[i] - a[id]);     bool safe = (i == 0 || a[i - 1] < a[i] - (d - rot));     if (safe && d >= rot) {       return front(i, d % rot);     }     return back(id, d - abs(a[i] - a[id]));   }   int back(int i, int d) {     if (done(i, d)) {       return i;     }     int id = lower_bound(a, a + n, a[i] - d) - a;     long long rot = 2 * abs(a[i] - a[id]);     bool safe = (i == n - 1 || a[i] + d - rot < a[i + 1]);     if (safe && d >= rot) {       return back(i, d % rot);     }     return front(id, d - abs(a[i] - a[id]));   }   int main() {     int m;     scanf( %d %d , &n, &m);     vector<pair<int, int>> p;     for (int i = 0; i < n; i++) {       scanf( %I64d , a + i);       p.emplace_back(a[i], i);     }     sort(a, a + n);     sort(p.begin(), p.end());     for (int i = 0; i < n; i++) {       to_sorted[p[i].second] = i;       to_nature[i] = p[i].second;     }     while (m--) {       int id, l;       scanf( %d %d , &id, &l);       id = to_sorted[id - 1];       printf( %d n , to_nature[front(id, l)] + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, viz[100005], cnt, nr, x[100005], nrans, ans[400005], rad;   vector<int> v[100005];   void dfs1(int nod) {     viz[nod] = 1;     nr += x[nod];     for (auto x : v[nod])       if (!viz[x]) dfs1(x);   }   void dfs(int nod, int tata) {     viz[nod] = 1;     nrans++;     ans[nrans] = nod;     x[nod] = 1 - x[nod];     for (auto xx : v[nod])       if (!viz[xx]) {         dfs(xx, nod);         nrans++;         ans[nrans] = nod;         x[nod] = 1 - x[nod];       }     if ((x[nod] % 2) && (nod != rad)) {       nrans++;       ans[nrans] = tata;       nrans++;       ans[nrans] = nod;       x[nod] = 1 - x[nod];       x[tata] = 1 - x[tata];     }   }   int main() {     int i, xx, y;     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> xx >> y;       v[xx].push_back(y);       v[y].push_back(xx);     }     for (i = 1; i <= n; i++) cin >> x[i];     for (i = 1; i <= n; i++)       if (!viz[i]) {         nr = 0;         dfs1(i);         if (nr % 2) cnt++;         if (cnt > 1) {           cout << -1;           return 0;         }       }     for (i = 1; i <= n; i++) viz[i] = 0;     for (i = 1; i <= n; i++)       if (x[i] % 2) {         rad = i;         break;       }     if (!rad) rad = 1;     dfs(rad, 0);     if (x[rad] % 2) nrans--;     cout << nrans <<   n ;     for (i = 1; i <= nrans; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, m, n, a[1000], b[1000], t = -1;     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < m; i++) {       cin >> b[i];     }     sort(a, a + n);     sort(b, b + m);     for (i = a[n - 1]; i < b[0]; i++) {       if ((2 * a[0]) <= i) {         t = i;         break;       }     }     cout << t;     return 0;   }