malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<int> g1[2111];   vector<int> g2[2111];   vector<int> v1, v2;   int s1[1111][1111];   int s2[1111][1111];   int N;   pair<int, int> dfs1(int v) {     pair<int, int> p = {1000, 0};     if (v1[v]) p = {v1[v], v1[v]};     for (auto to : g1[v]) {       auto cur = dfs1(to);       p.first = min(cur.first, p.first);       p.second = max(cur.second, p.second);     }     for (int i = 1; i <= p.first; ++i)       for (int j = p.second; j <= N; ++j) s1[i][j]++;     return p;   }   pair<int, int> dfs2(int v) {     pair<int, int> p = {1000, 0};     if (v2[v]) p = {v2[v], v2[v]};     for (auto to : g2[v]) {       auto cur = dfs2(to);       p.first = min(cur.first, p.first);       p.second = max(cur.second, p.second);     }     for (int i = 1; i <= p.first; ++i)       for (int j = p.second; j <= N; ++j) s2[i][j]++;     return p;   }   int dp[1111];   int main() {     cin >> N;     int n1;     cin >> n1;     for (int i = 2; i <= n1; ++i) {       int t;       cin >> t;       g1[t].push_back(i);     }     v1.assign(n1 + 1, 0);     for (int i = 1; i <= N; ++i) {       int t;       cin >> t;       v1[t] = i;     }     int n2;     cin >> n2;     for (int i = 2; i <= n2; ++i) {       int t;       cin >> t;       g2[t].push_back(i);     }     v2.assign(n2 + 1, 0);     for (int i = 1; i <= N; ++i) {       int t;       cin >> t;       v2[t] = i;     }     dfs1(1);     dfs2(1);     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= N; ++j) {         s1[i][j] = min(s1[i][j], n1 - 1);         s2[i][j] = min(s2[i][j], n2 - 1);       }     }     for (int i = 1; i <= N; ++i) {       int mx1 = s1[1][i];       int mx2 = s2[1][i];       dp[i] = max(mx1, mx2);       for (int j = i; j >= 2; --j) {         {           int cur = s1[j][i];           dp[i] = max(dp[i], dp[j - 1] + cur);         }         {           int cur = s2[j][i];           dp[i] = max(dp[i], dp[j - 1] + cur);         }       }     }     cout << dp[N] << endl;   }
#include <bits/stdc++.h>   int main() {     int s, v1, v2, t1, t2;     scanf( %d %d %d %d %d , &s, &v1, &v2, &t1, &t2);     int a = s * v1 + 2 * t1;     int b = s * v2 + 2 * t2;     if (a == b) {       printf( Friendship n );     } else if (a < b) {       printf( First n );     } else {       printf( Second n );     }   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 5e5 + 10;   long long N, arr[maxn], use[maxn];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N;     for (register long long i = 1; i <= N; ++i) {       cin >> arr[i];     }     sort(arr + 1, arr + 1 + N);     long long pos = N / 2, l = pos + 1, r = N, ans = N;     while (pos >= 1) {       if (l <= r && arr[pos] * 2 <= arr[r]) {         --ans, --r;       }       pos--;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     int ones = 0, zeros = 0;     for (char c : s) {       if (c ==  n ) ones++;       if (c ==  r ) zeros++;     }     while (ones--) cout <<  1  ;     while (zeros--) cout <<  0  ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   T pow_mod(T a, U b, int mod) {     T r = 1;     for (; b > 0; b >>= 1) {       if (b & 1) r = (long long)r * a % mod;       a = (long long)a * a % mod;     }     return r;   }   enum bit_op { AND, OR, XOR };   namespace bitwise_transform {   template <int P, typename T>   inline void fix(T &x) {     if (x >= P)       x -= P;     else if (x < 0)       x += P;   }   template <bit_op B, int P, bool inv = false, typename T>   void transform(T a[], int n) {     for (int len = 1; len < n; len <<= 1)       for (int i = 0; i < n; i += len << 1)         for (int j = i; j < i + len; ++j) {           T u = a[j], v = a[j + len];           if (B == AND) a[j] = v - u * inv, a[j + len] = u + v * (!inv);           if (B == OR) a[j] = u * (!inv) + v, a[j + len] = u - inv * v;           if (B == XOR) a[j] = u + v, a[j + len] = u - v;           if (P != -1) fix<P>(a[j]), fix<P>(a[j + len]);         }     if (B == XOR && inv) {       int in = pow_mod(n, P - 2, P);       for (int i = 0; i < n; ++i) {         if (P == -1)           a[i] /= n;         else           a[i] = (long long)a[i] * in % P;       }     }   }   template <bit_op B, int P = -1, typename T>   vector<T> convolve(vector<T> a, vector<T> b) {     int n = max(a.size(), b.size()), sz = 1;     while (sz < n) sz <<= 1;     a.resize(sz);     b.resize(sz);     transform<B, P>(a.data(), sz);     transform<B, P>(b.data(), sz);     for (int i = 0; i < sz; ++i) {       if (P == -1)         a[i] *= b[i];       else         a[i] = (long long)a[i] * b[i] % P;     }     transform<B, P, true>(a.data(), sz);     return a;   }   }  // namespace bitwise_transform   const int mod = 998244353, B = 36, C = B / 2;   inline void add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   inline int bp(int x) { return __builtin_popcount(x); }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     vector<long long> b(B);     for (long long i = 0, x; i < n; ++i) {       cin >> x;       for (int j = B - 1; j >= 0; --j)         if ((x = min(x ^ b[j], x)) >> j & 1) {           b[j] = x;           break;         }     }     int len = B - count(b.begin(), b.end(), 0LL);     vector<int> y(1 << C);     for (int i = 0; i < 1 << C; ++i) {       int z = i;       for (int j = C - 1; j >= 0; --j)         if (z >> j & 1) z ^= b[j];       if (!z) y[i] = 1;     }     vector<int> ans(m + 1);     for (int k = 0; k < B; ++k) {       vector<int> x(1 << C);       for (int i = 0; i < 1 << C; ++i)         if (bp(i) == k) {           long long z = (long long)i << C;           for (int j = B - 1; j >= C; --j)             if (z >> j & 1) z ^= b[j];           if (!(z >> C)) x[z & ((1 << C) - 1)] += 1;         }       auto z = bitwise_transform::convolve<XOR, mod>(x, y);       for (int i = z.size() - 1; i >= 0; --i)         if (z[i]) add(ans[k + bp(i)], z[i]);     }     int p = pow_mod(2, n - len, mod);     for (int i = 0; i <= m; ++i)       cout << (long long)ans[i] * p % mod <<    n [i == m];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, x, y, l, r, fact[200001], inv[200001], mod = 1e9 + 7;   map<int, int> m;   int powlog(int a, int b) {     if (b == 0) return 1;     int ret = powlog(a, b / 2);     if (b % 2) return 1LL * ret * ret % mod * a % mod;     return 1LL * ret * ret % mod;   }   int C(int n, int r) { return 1LL * fact[n] * inv[r] % mod * inv[n - r] % mod; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     fact[0] = inv[0] = 1;     for (int i = 1; i <= 200000; i++) {       fact[i] = 1LL * i * fact[i - 1] % mod;       inv[i] = powlog(fact[i], mod - 2);     }     cin >> n >> k;     for (int i = 0; i < n && cin >> x >> y; i++) m[x]++, m[y + 1]--;     long long ans = 0;     int prev = 0, lines = 0;     for (auto &i : m) {       if (lines >= k)         ans = (ans + 1LL * (i.first - prev) * C(lines, k) % mod) % mod;       lines += i.second;       prev = i.first;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   inline T range(T l, T r) {     return uniform_int_distribution<T>(l, r)(rng);   }   inline void setin(string s) { freopen(s.c_str(),  r , stdin); }   inline void setout(string s) { freopen(s.c_str(),  w , stdout); }   template <typename T>   void Min(T &a, T b) {     a = min(a, b);   }   template <typename T>   void Max(T &a, T b) {     a = max(a, b);   }   const int K = 2;   const int mod[K] = {998244353, 1000000007};   const int inf = 0x3f3f3f3f;   const int N = 1e4 + 15;   int n, q;   int dp[K][N];   bool ans[N];   struct query {     int x, val, t;     bool operator<(const query &rhs) const {       return make_pair(x, t) < make_pair(rhs.x, rhs.t);     }   };   vector<query> is;   inline int add(int a, int b, int mod) {     a += b;     if (a >= mod)       a -= mod;     else if (a < 0)       a += mod;     return a;   }   inline void add_t(int &a, int b, int mod) { a = add(a, b, mod); }   inline int mt(int a, int b, int mod) { return 1ll * a * b % mod; }   inline void add(int x, int coef) {     if (coef == 1)       for (int i = n - x; i >= 0; --i)         for (int j = 0; j < K; ++j) add_t(dp[j][i + x], dp[j][i], mod[j]);     else       for (int i = 0; i <= n - x; ++i)         for (int j = 0; j < K; ++j) add_t(dp[j][i + x], -dp[j][i], mod[j]);   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n >> q;     for (int i = 1; i <= q; ++i) {       int l, r, x;       cin >> l >> r >> x;       is.push_back({l, x, 1});       is.push_back({r + 1, x, -1});     }     sort(is.begin(), is.end());     for (int j = 0; j < K; ++j) dp[j][0] = 1;     for (int i = 1, j = 0; i <= n; ++i) {       while (j < is.size() && is[j].x <= i) {         add(is[j].val, is[j].t);         ++j;       }       for (int y = 1; y <= n; ++y) {         bool flag = false;         for (int j = 0; j < K; ++j) flag |= dp[j][y];         ans[y] |= flag;       }     }     int cnt = 0;     for (int i = 1; i <= n; ++i) cnt += ans[i];     cout << cnt <<   n ;     for (int i = 1; i <= n; ++i)       if (ans[i]) cout << i <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double PI = 3.14159265358979323846;   int rx[8] = {1, 1, 1, -1, -1, -1, 0, 0};   int ry[8] = {0, -1, 1, 0, -1, 1, 1, -1};   int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int n, k, a, b, c, d, h;   bool u[1111];   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k >> a >> b >> c >> d;     if (k <= n || n == 4)       cout << -1;     else {       u[a] = 1, u[b] = 1, u[c] = 1, u[d] = 1;       for (int i = 1; i <= n; i++) {         if (!u[i]) {           h = i;           u[i] = 1;           break;         }       }       cout << a <<     << c <<     << h <<     << d <<    ;       for (int i = 1; i <= n; i++) {         if (!u[i]) cout << i <<    ;       }       cout << b << endl;       cout << c <<     << a <<     << h <<     << b <<    ;       for (int i = n; i >= 1; i--) {         if (!u[i]) cout << i <<    ;       }       cout << d;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long in() {     int32_t x;     scanf( %d , &x);     return x;   }   inline long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   inline void read(long long *a, long long n) {     for (long long i = 0; i < n; i++) a[i] = in();   }   inline void readL(long long *a, long long n) {     for (long long i = 0; i < n; i++) a[i] = lin();   }   const long long maxn = 100 + 10;   const long long mod = 1e9 + 7;   const long long MAX_VAL = 1e18 + 10;   const long long MAGIC = 350;   long long n, m;   vector<pair<long long, long long> > g[maxn];   long long dp[maxn][maxn][27];   long long ret[maxn][maxn];   inline long long dfs(long long a, long long b, long long pre) {     if (pre >= 26) return 1;     if (dp[a][b][pre] + 1) return dp[a][b][pre];     for (auto u : g[a]) {       if (u.second >= pre) {         long long getRes = dfs(b, u.first, u.second);         if (getRes == 1) return dp[a][b][pre] = 0;       }     }     return dp[a][b][pre] = 1;   }   int32_t main() {     n = in(), m = in();     memset(dp, -1, sizeof dp);     for (long long i = 0; i < m; i++) {       long long v = in() - 1, u = in() - 1;       char ch;       do {         ch = getchar();       } while (!isalpha(ch));       g[v].push_back({u, ch -  a });     }     for (long long a = 0; a < n; a++, cout <<   n ) {       for (long long b = 0; b < n; b++) {         ret[a][b] = dfs(a, b, 0);         if (ret[a][b] == 0)           cout <<  A ;         else           cout <<  B ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300000 + 10;   const long long MOD = 1000000000 + 7;   const long long INF = 10000000;   vector<long long> Poi;   unordered_map<long long, long long> koj;   long long q, SEG[4 * N][2], lazy[4 * N];   vector<pair<int, pair<long long, long long>>> Q;   void modify(int id, int l, int r, int x) {     if (x == -1) return;     if (x == 0) {       SEG[id][0] = INF;       SEG[id][1] = l;       lazy[id] = x;       return;     }     if (x == 1) {       SEG[id][0] = l;       SEG[id][1] = INF;       lazy[id] = x;       return;     }     if (lazy[id] == -1) {       swap(SEG[id][0], SEG[id][1]);       lazy[id] = x;       return;     }     if (lazy[id] == 2) {       swap(SEG[id][0], SEG[id][1]);       lazy[id] = -1;       return;     }     if (lazy[id] == 0) {       SEG[id][0] = l;       SEG[id][1] = INF;       lazy[id] = 1;       return;     }     SEG[id][0] = INF;     SEG[id][1] = l;     lazy[id] = 0;     return;   }   void shift(int id, int l, int r) {     int mid = (l + r) >> 1;     modify(id << 1, l, mid, lazy[id]);     modify(id << 1 | 1, mid, r, lazy[id]);     lazy[id] = -1;     return;   }   void build(int id, int l, int r) {     if (r - l == 1) {       SEG[id][0] = l;       SEG[id][1] = INF;       return;     }     int mid = (l + r) >> 1;     build(id << 1, l, mid);     build(id << 1 | 1, mid, r);     SEG[id][0] = l;     SEG[id][1] = INF;     return;   }   void update(int id, int lq, int rq, int x, int l, int r) {     if (rq <= l || r <= lq) {       return;     }     if (lq <= l && r <= rq) {       modify(id, l, r, x);       return;     }     int mid = (l + r) >> 1;     shift(id, l, r);     update(id << 1, lq, rq, x, l, mid);     update(id << 1 | 1, lq, rq, x, mid, r);     SEG[id][0] = min(SEG[id << 1][0], SEG[id << 1 | 1][0]);     SEG[id][1] = min(SEG[id << 1][1], SEG[id << 1 | 1][1]);     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> q;     while (q--) {       long long x, l, r;       cin >> x >> l >> r;       Poi.push_back(l);       Poi.push_back(r);       Poi.push_back(r + 1);       Q.push_back({x, {l, r}});     }     Poi.push_back(1);     sort(Poi.begin(), Poi.end());     Poi.push_back(1000000000000000001);     Poi.resize(unique(Poi.begin(), Poi.end()) - Poi.begin());     for (int i = 0; i < Poi.size(); i++) {       koj[Poi[i]] = i + 1;     }     for (int i = 0; i < 4 * N; i++) {       SEG[i][0] = INF;       SEG[i][1] = INF;     }     memset(lazy, -1, sizeof lazy);     build(1, 1, N);     for (auto u : Q) {       update(1, koj[u.second.first], koj[u.second.second] + 1, u.first - 1, 1, N);       cout << Poi[SEG[1][0] - 1] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     size_t n, m, q;     cin >> n >> m >> q;     vector<uint32_t> perm(n);     for (size_t i = 0; i < n; ++i) {       cin >> perm[i];       perm[i]--;     }     vector<uint32_t> a(m);     for (size_t i = 0; i < m; ++i) {       cin >> a[i];       a[i]--;     }     vector<uint32_t> next(n);     next[perm.back()] = perm.front();     for (size_t i = 0; i < n - 1; ++i) {       next[perm[i]] = perm[i + 1];     }     constexpr static auto IMPOSSIBLE = numeric_limits<size_t>::max();     size_t log2n = 8 * sizeof(int) - __builtin_clz((int)n);     vector<vector<size_t>> cycle_ends(log2n);     for (size_t i = 0; i < log2n; ++i) {       cycle_ends[i].resize(m);     }     vector<size_t> closest_next(n, IMPOSSIBLE);     for (int i = m - 1; i >= 0; --i) {       cycle_ends[0][i] = closest_next[next[a[i]]];       closest_next[a[i]] = i;     }     for (size_t i = 1; i < log2n; ++i) {       for (size_t j = 0; j < m; ++j) {         auto next = cycle_ends[i - 1][j];         cycle_ends[i][j] =             next == IMPOSSIBLE ? IMPOSSIBLE : cycle_ends[i - 1][next];       }     }     vector<size_t> bits;     for (size_t i = 0; i < log2n; ++i) {       if (((n - 1) >> i) & 1) {         bits.emplace_back(i);       }     }     vector<size_t> min_right(m);     size_t closest = IMPOSSIBLE;     for (int i = m - 1; i >= 0; --i) {       size_t next = i;       for (auto j : bits) {         next = cycle_ends[j][next];         if (next == IMPOSSIBLE) {           break;         }       }       closest = min(closest, next);       min_right[i] = closest;     }     for (size_t i = 0; i < q; ++i) {       size_t l, r;       cin >> l >> r;       cout << (int)(min_right[l - 1] <= r - 1);     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int rel[50][50], tk[50], vis[50];   int x[20][3], p, alone[50];   int dfs(int i, int r, int n) {     vis[i] = r;     int j, k = 1;     for (j = 1; j <= n; j++) {       if (rel[i][j] && vis[j] == 0) {         k += dfs(j, r, n);       }     }     return k;   }   int main() {     int n, m, i, j, k, l, l1;     scanf( %d , &n);     scanf( %d , &m);     for (i = 1; i <= m; i++) {       scanf( %d , &j);       scanf( %d , &k);       rel[j][k] = 1;       rel[k][j] = 1;     }     l = 0;     for (i = 1; i <= n; i++) {       if (vis[i]) continue;       k = dfs(i, i, n);       if (k > 3) {         printf( -1 );         return 0;       }       if (k == 1) {         l++;         alone[l] = i;       }     }     memset(vis, 0, sizeof(vis));     l1 = 1;     for (i = 1; i <= n; i++) {       if (vis[i]) continue;       k = dfs(i, i, n);       if (k > 1) {         p++;         m = 0;         for (j = 1; j <= n; j++) {           if (vis[j] == i) {             x[p][m] = j;             m++;           }         }         if (k == 2) {           if (l1 > l) {             printf( -1 );             return 0;           }           x[p][2] = alone[l1];           l1++;         }       }     }     p++;     m = 0;     for (i = l1; i <= l; i++) {       x[p][m] = alone[i];       m++;       if (m == 3) {         m = 0;         p++;       }     }     for (i = 1; i < p; i++) {       for (j = 0; j < 3; j++) {         printf( %d  , x[i][j]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     scanf( %d , &q);     while (q--) {       int n;       scanf( %d , &n);       vector<int> a(n);       for (int i = 0; i < n; i++) scanf( %d , &a[i]);       sort(a.begin(), a.end());       a.erase(unique(a.begin(), a.end()), a.end());       n = a.size();       int ans = a.back();       for (int i = n - 1; i >= 0; i--) {         if (i >= 2) {           if (ans > a[i] + a[i - 1] + a[i - 2]) break;         }         for (int j = i - 1; j >= 0; j--) {           if (j >= 1) {             if (ans > a[i] + a[j] + a[j - 1]) break;           }           if (a[i] % a[j]) {             ans = max(ans, a[i] + a[j]);             for (int k = j - 1; k >= 0; k--) {               if (ans > a[i] + a[j] + a[k]) break;               if ((a[i] % a[k]) && (a[j] % a[k])) {                 ans = max(ans, a[i] + a[j] + a[k]);                 break;               }             }           }         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int n, a[N], rt = 1, ba[30], sta[N], top = 0;   vector<int> e[N];   long long ans;   void dfs(int u, int ff) {     sta[++top] = u;     if (ff) {       long long w = a[sta[top - 1]];       int i = 1;       for (; top - ba[i] > 0; i++)         if (w > (long long)(i + 1) * a[sta[top - ba[i]]])           w = (long long)(i + 1) * a[sta[top - ba[i]]];       if (w > (long long)(i + 1) * a[rt]) w = (long long)(i + 1) * a[rt];       ans += w + (long long)a[u];     }     for (auto v : e[u])       if (v ^ ff) dfs(v, u);     --top;   }   int main() {     ba[0] = 1;     for (int i = 1; i < 25; i++) ba[i] = ba[i - 1] * 2;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] < a[rt]) rt = i;     }     for (int i = 1, x, y; i < n; i++)       scanf( %d%d , &x, &y), e[x].push_back(y), e[y].push_back(x);     dfs(rt, 0), printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     int x1, y1, r1, x2, y2, r2;     scanf( %d %d %d %d %d %d , &x1, &y1, &r1, &x2, &y2, &r2);     double ans;     ans = (sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) - r1 - r2) / 2;     if (ans < 0)       if (r1 > r2)         ans = (r1 - r2 - sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))) / 2;       else         ans = ans =             (r2 - r1 - sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))) / 2;     if (ans < 0)       printf( 0.000000000 );     else       printf( %lf , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   long long quickpow(long long a, long long b) {     long long ans = 1;     a = a % mod;     while (b > 0) {       if (b % 2) ans = ans * a;       b = b / 2;       a = a * a;     }     return ans;   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   long long a[500005];   long long sum[500005];   long long tot = 0;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + a[i];     }     tot += sum[n];     for (int i = 1; i <= n - 1; i++) {       tot += (sum[n] - sum[i - 1]);     }     cout << tot << endl;   }
#include <iostream>   #include <string>   #include <vector>   #include <algorithm>   #include <sstream>   #include <queue>   #include <deque>   #include <bitset>   #include <iterator>   #include <list>   #include <stack>   #include <map>   #include <set>   #include <functional>   #include <numeric>   #include <utility>   #include <limits>   #include <time.h>   #include <math.h>   #include <stdio.h>   #include <string.h>   #include <stdlib.h>   #include <assert.h>      using namespace std;      #define ll long long int   #define nl cout<<  n ;   #define pb push_back      void solve(){       ll a[4],b[4],i;       for(i=0;i<4;i++){           cin>>a[i];           b[i]=a[i];       }       ll c=max(a[0],a[1]),d=max(a[2],a[3]);       sort(b,b+4);       if(max(b[3],b[2])==max(c,d) && min(b[3],b[2])==min(c,d))           cout<< YES n ;       else           cout<< NO n ;   }      int main(){       ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);       int t=1;       cin>>t;       while(t--){           solve();       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> odd;   int main() {     int n, t;     cin >> n;     long long cnt = 0, res = -1e9;     for (int i = 0; i < n; i++) {       cin >> t;       if (abs(t) % 2 == 1)         odd.push_back(t);       else if (t > 0)         cnt += t;     }     sort(odd.begin(), odd.end());     bool flag = 0;     int sz = odd.size();     for (int i = sz - 1; i >= 0; i--) {       cnt += odd[i];       if (abs(cnt) % 2 == 1) res = max(cnt, res);     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long double n, k;     cin >> n >> k;     string s;     cin >> s;     set<string, greater<string> > st;     queue<string> stk;     stk.push(s);     while (k && !stk.empty()) {       string temp = stk.front();       stk.pop();       if (st.find(temp) == st.end()) {         st.insert(temp);         k--;         for (long double i = 0; i < temp.length(); i++) {           string s1 = temp;           s1.erase(s1.begin() + i);           if (s1.size()) stk.push(s1);         }       }     }     long double ans = 0;     if (k == 0 || (k == 1 && stk.empty())) {       for (auto i = st.begin(); i != st.end(); i++) {         ans += (n - (*i).length());       }       if (stk.empty()) ans += n;       cout << ans << endl;     } else {       cout << -1 << endl;     }   }