malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool gt(long double a, long double b) { return a > b + 1e-12; }   int n, m;   vector<pair<bool, pair<int, int> > > pt, org;   pair<int, int> o;   inline bool left_turn(const pair<int, int> &a, const pair<int, int> &b,                         const pair<int, int> &c) {     return 1LL * (b.first - a.first) * (c.second - b.second) -                1LL * (b.second - a.second) * (c.first - b.first) >            0;   }   inline bool cmp(pair<bool, pair<int, int> > a, pair<bool, pair<int, int> > b) {     return left_turn(o, a.second, b.second);   }   inline bool by_Y(pair<bool, pair<int, int> > a, pair<bool, pair<int, int> > b) {     return a.second.second < b.second.second;   }   int main() {     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     org.resize(n + m);     for (register int i = (0); i < (int)(n); ++i)       cin >> org[i].second.first >> org[i].second.second, org[i].first = 0;     for (register int i = (0); i < (int)(m); ++i)       cin >> org[i + n].second.first >> org[i + n].second.second,           org[i + n].first = 1;     int tot = 0;     sort((org).begin(), (org).end(), by_Y);     for (register int rep = (0); rep < (int)(((int)(org).size())); ++rep)       if (org[rep].first == 0) {         pt.clear();         for (register int i = (0); i < (int)(((int)(org).size())); ++i)           if (org[rep].second <= org[i].second && i != rep) pt.push_back(org[i]);         o = org[rep].second;         sort((pt).begin(), (pt).end(), cmp);         for (register int oth = (0); oth < (int)(((int)(pt).size())); ++oth)           if (pt[oth].first == 0) {             pair<int, int> worst;             bool wfound = false;             for (register int i = (1); i < (int)(((int)(pt).size())); ++i) {               pair<bool, pair<int, int> > next =                   pt[(oth + i) % ((int)(pt).size())];               if (!left_turn(o, pt[oth].second, next.second)) break;               if (next.first == 1 &&                   (wfound == false ||                    left_turn(pt[oth].second, worst, next.second)))                 worst = next.second, wfound = true;               if (next.first == 0 &&                   (wfound == false ||                    left_turn(pt[oth].second, worst, next.second)))                 tot++;             }           }       }     cout << tot << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int res = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (isdigit(ch)) {       res = res * 10 + ch -  0 ;       ch = getchar();     }     return res * f;   }   namespace qiqi {   const int N = 3005;   int n, m, ecnt, head[N], a[N], siz[N];   pair<long long, long long> f[N][N], g[N];   struct Edge {     int v, nxt;   } e[N << 1];   inline void add(int u, int v) {     e[++ecnt] = (Edge){v, head[u]};     head[u] = ecnt;   }   void dfs(int u, int fa) {     f[u][siz[u] = 1] = make_pair(0, a[u]);     for (int k = head[u], v = e[k].v; k; v = e[k = e[k].nxt].v)       if (v != fa) {         dfs(v, u);         for (int i = (1); i <= (siz[u] + siz[v]); ++i) g[i] = make_pair(-1, 0);         for (int i = (siz[u]); i >= (1); --i)           for (int j = (siz[v]); j >= (1); --j) {             g[i + j] = max(g[i + j], make_pair(f[u][i].first + f[v][j].first +                                                    (f[v][j].second > 0),                                                f[u][i].second));             g[i + j - 1] =                 max(g[i + j - 1], make_pair(f[u][i].first + f[v][j].first,                                             f[u][i].second + f[v][j].second));           }         siz[u] += siz[v];         for (int i = (1); i <= (siz[u]); ++i) f[u][i] = g[i];       }   }   void main() {     memset(head, ecnt = 0, sizeof(head));     n = read();     m = read();     for (int i = (1); i <= (n); ++i) a[i] = read();     for (int i = (1); i <= (n); ++i) a[i] = read() - a[i];     int u, v;     for (int i = (2); i <= (n); ++i) {       u = read();       v = read();       add(u, v);       add(v, u);     }     dfs(1, 0);     printf( %lld n , f[1][m].first + (f[1][m].second > 0));   }   }  // namespace qiqi   int main() {     int T = read();     while (T--) qiqi::main();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int sum(long long int n) {     long long int s2um = 0;     while (n > 0) {       s2um += n % 10;       n = n / 10;     }     return s2um;   }   long long int answer(long long int n) {     long long int x = 0, y = 0;     while (10 * y + 9 < n) {       y = 10 * y + 9;       x = x + 9;     }     long long int m = n - y;     x += sum(m);     return x;   }   int main() {     ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     std::cout.tie(NULL);     long long int n;     cin >> n;     cout << answer(n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200100;   int n, l, r, m, a[N], b[N], c, pos, mi, ma;   pair<int, int> t[4 * N];   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v].first = a[tl];       t[v].second = b[tl];       return;     }     int tm = (tl + tr) / 2;     build(2 * v, tl, tm);     build(2 * v + 1, tm + 1, tr);     t[v].first = max(t[2 * v].first, t[2 * v + 1].first);     t[v].second = min(t[2 * v].second, t[2 * v + 1].second);     return;   }   void get(int v, int tl, int tr, int l, int r) {     if (l > r) return;     if (tl == l && tr == r) {       ma = max(ma, t[v].first);       mi = min(mi, t[v].second);       return;     }     int tm = (tl + tr) / 2;     get(2 * v, tl, tm, l, min(r, tm));     get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     a[n + 1] = 1e9 - 2;     for (int i = 1; i <= n; i++) cin >> b[i];     b[n + 1] = -1e9 - 2;     build(1, 1, n);     long long ans = 0;     for (int i = 1; i <= n; i++)       if (a[i] - b[i] < 1) {         l = i;         r = n + 1;         while (l < r) {           c = (l + r) / 2;           mi = 1e9 + 2;           ma = -1e9 - 2;           get(1, 1, n, i, c);           if (mi > ma)             l = c + 1;           else             r = c;         }         pos = l;         l = i;         r = n + 1;         while (l < r) {           c = (l + r) / 2;           mi = 1e9 + 2;           ma = -1e9 - 2;           get(1, 1, n, i, c);           if (mi >= ma)             l = c + 1;           else             r = c;         }         ans += max(l - pos, 0);       }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int n, x, y, sum = 0;     cin >> n;     long long int a[n + 1][n + 1];     for (long long int i = 1; i <= n; i++)       for (long long int j = 1; j <= n; j++) {         cin >> a[i][j];         if (a[i][j] == 0) {           y = j;           x = i;         }       }     set<long long int> s;     if (n == 1) {       cout <<  1 ;       exit(0);     }     if (x != y) {       for (long long int i = 1; i <= n; i++) sum += a[i][i];       s.insert(sum);     }     if (x != n - y + 1) {       sum = 0;       for (long long int i = 1; i <= n; i++) sum += a[i][n - i + 1];       s.insert(sum);     }     for (long long int i = 1; i <= n; i++) {       if (i == x) continue;       sum = 0;       for (long long int j = 1; j <= n; j++) sum += a[i][j];       s.insert(sum);     }     for (long long int j = 1; j <= n; j++) {       if (j == y) continue;       sum = 0;       for (long long int i = 1; i <= n; i++) sum += a[i][j];       s.insert(sum);     }     long long int val = *(s.begin());     sum = 0;     for (long long int i = 1; i <= n; i++) sum += a[i][y];     long long int t = val - sum;     if ((long long int)s.size() > 1 || t <= 0) {       cout <<  -1 ;       exit(0);     }     a[x][y] = t;     sum = 0;     long long int sum1 = 0, sum2 = 0;     for (long long int i = 1; i <= n; i++) sum += a[x][i];     for (long long int i = 1; i <= n; i++) sum1 += a[i][i];     for (long long int i = 1; i <= n; i++) sum2 += a[i][n - i + 1];     if (sum != val || sum1 != val || sum2 != val) {       cout <<  -1 ;       exit(0);     }     cout << t;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long Inf = 1e18;   const int N = 2e6 + 10;   const int mod = 1e9 + 7;   int gi() {     int x = 0, o = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) o = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * o;   }   template <typename T>   bool chkmax(T &a, T b) {     return a < b ? a = b, 1 : 0;   };   template <typename T>   bool chkmin(T &a, T b) {     return a > b ? a = b, 1 : 0;   };   int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }   int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }   void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); }   void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); }   int n, p[N], a[N], pw[N], cnt[N];   int pri[N], tot = 0, d[N];   bool vis[N];   void init() {     const int n = 2e6;     for (int i = 2; i <= n; i++) {       if (!vis[i]) pri[++tot] = i, d[i] = i;       for (int j = 1; j <= tot && i * pri[j] <= n; j++) {         vis[i * pri[j]] = 1;         d[i * pri[j]] = pri[j];         if (i % pri[j] == 0) break;       }     }   }   int qpow(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return ret;   }   int main() {     init();     cin >> n;     for (int i = 1; i <= n; i++) p[i] = gi();     sort(p + 1, p + n + 1);     for (int i = n; i; i--) {       if (!pw[p[i]])         pw[p[i]] = cnt[p[i]] = 1, a[i] = p[i];       else {         int x = p[i] - 1;         a[i] = p[i] - 1;         while (x > 1) {           int y = d[x], sum = 0;           while (x % y == 0) x /= y, sum++;           if (pw[y] < sum)             pw[y] = sum, cnt[y] = 1;           else if (pw[y] == sum)             cnt[y]++;         }       }     }     int tag = 0;     for (int i = n; i; i--) {       int x = a[i], fl = 1;       while (x > 1) {         int y = d[x], sum = 0;         while (x % y == 0) x /= y, sum++;         if (sum == pw[y] && cnt[y] == 1) fl = 0;       }       tag |= fl;     }     int ans = 1;     for (int i = 2; i <= 2000000; i++) ans = 1ll * ans * qpow(i, pw[i]) % mod;     printf( %d n , add(ans, tag));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXARR = 2e5 + 5, MAXVAL = 1e6 + 5, MOD = 1e9 + 7, INF = 2147483647;   const long long INFLL = (1LL << 62);   int n, d, m;   int last[MAXARR];   pair<long long, long long> stop[MAXARR];   stack<pair<long long, long long> > st;   long long ans = 0LL;   template <class T>   void maximize(T &x, T y) {     if (x < y) x = y;   }   template <class T>   void minimize(T &x, T y) {     if (x > y) x = y;   }   bool get_bit(int i, int k) { return ((k >> (i - 1)) & 1); }   int change_bit(int i, int k) { return (k ^ (1 << (i - 1))); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> d >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> stop[i].first >> stop[i].second;     }     stop[++m] = pair<long long, long long>(0, 0);     stop[++m] = pair<long long, long long>(d, 0);     sort(stop + 1, stop + m + 1);     for (int i = 1; i <= m; i++) {       last[i] = INF;     }     for (int i = 1; i <= m; i++) {       while (!st.empty() && st.top().first > stop[i].second) {         last[st.top().second] = i;         st.pop();       }       st.push(pair<long long, long long>(stop[i].second, i));     }     long long now = n;     for (int i = 2; i <= m; i++) {       now -= stop[i].first - stop[i - 1].first;       if (now < 0) {         cout <<  -1 ;         exit(0);       }       if (last[i] != INF && stop[last[i]].first - stop[i].first <= n) {         ans += 1LL * max(0LL, (stop[last[i]].first - stop[i].first - now)) *                stop[i].second;         now = max(now, stop[last[i]].first - stop[i].first);       } else if (n + stop[i].first < d) {         ans += 1LL * (n - now) * stop[i].second;         now = n;       } else {         ans += 1LL * max(0LL, d - stop[i].first - now) * stop[i].second;         now = max(now, d - stop[i].first);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     std::ios_base::sync_with_stdio(0), cin.tie(0);     string s, t;     cin >> s >> t;     int a[26] = {};     int n = s.size(), m = t.size();     for (int i = 0; i < n; ++i) a[s[i] -  a ]++;     bool ok = 0;     if (n < m) {       s =   ;       for (int i = 0; i < n && !ok; ++i) {         if (a[t[i] -  a ]) {           a[t[i] -  a ]--;           s += t[i];           continue;         } else {           for (int j = t[i] -  a  + 1; j < 26; ++j) {             if (a[j]) {               a[j]--;               s += char( a  + j);               ok = 1;               break;             }           }           if (ok) break;           for (int j = i - 1; j >= 0 && !ok; --j) {             a[s[j] -  a ]++;             s.pop_back();             for (int k = t[j] -  a  + 1; k < 26; ++k) {               if (a[k]) {                 a[k]--;                 s += char(k +  a );                 ok = 1;                 break;               }             }           }           if (!ok) {             cout << -1;             return 0;           }         }       }       if (!ok) {         cout << -1;         return 0;       }       for (int i = 0; i < 26; ++i) {         for (int j = 0; j < a[i]; ++j) {           s += char( a  + i);         }       }       cout << s;       return 0;     }     s =   ;     for (int i = 0; i < m && !ok; ++i) {       if (a[t[i] -  a ]) {         a[t[i] -  a ]--;         s += t[i];         continue;       } else {         for (int j = t[i] -  a  + 1; j < 26; ++j) {           if (a[j]) {             a[j]--;             s += char( a  + j);             ok = 1;             break;           }         }         if (ok) break;         for (int j = i - 1; j >= 0 && !ok; --j) {           a[s[j] -  a ]++;           s.pop_back();           for (int k = t[j] -  a  + 1; k < 26; ++k) {             if (a[k]) {               a[k]--;               s += char(k +  a );               ok = 1;               break;             }           }         }         if (!ok) {           cout << -1;           return 0;         }       }     }     if (!ok) {       if (n == m) {         if (next_permutation(s.begin(), s.end()))           cout << s;         else           cout << -1;         return 0;       }     }     for (int i = 0; i < 26; ++i) {       for (int j = 0; j < a[i]; ++j) {         s += char( a  + i);       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int power(int a, int n, int m) {     if (n <= 0) return 1;     if (n % 2 == 1) {       return ((int)(((long long)power(a, n - 1, m) * a) % m));     } else {       int k = power(a, n / 2, m);       return ((int)(((long long)k * k) % m));     }   }   int main() {     long long n, m;     cin >> n >> m;     long long ans = (power(3, n, m) - 1) % m;     if (ans < 0) ans += m;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   const int N = 100005;   long long num1[N], num2[N], num3[N];   void init() {     memset(num1, 0, sizeof(num1));     memset(num2, 0, sizeof(num2));     memset(num3, 0, sizeof(num3));     for (int i = 1; i < N; ++i) {       for (int j = i; j < N; j += i) {         num1[j] += 1;       }     }     num2[0] = 0;     for (int i = 1; i < N; ++i) {       num2[i] = num2[i - 1] + i;     }     num3[0] = 0;     for (int i = 1; i < N; ++i) {       num3[i] = num3[i - 1] + num2[i];     }   }   int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }   int main() {     init();     int t;     scanf( %d , &t);     while (t--) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       int gcd_3 = gcd(x, gcd(y, z));       int gcd_xy = gcd(x, y);       int gcd_yz = gcd(y, z);       int gcd_xz = gcd(x, z);       long long g_3 = num1[gcd_3];       long long g_xy = num1[gcd_xy] - num1[gcd_3];       long long g_xz = num1[gcd_xz] - num1[gcd_3];       long long g_yz = num1[gcd_yz] - num1[gcd_3];       long long g_x = num1[x] + num1[gcd_3] - num1[gcd_xy] - num1[gcd_xz];       long long g_y = num1[y] + num1[gcd_3] - num1[gcd_xy] - num1[gcd_yz];       long long g_z = num1[z] + num1[gcd_3] - num1[gcd_xz] - num1[gcd_yz];       long long cnt = 0;       cnt += num3[g_3];       cnt += num2[g_3] * (g_xy + g_yz + g_xz + g_x + g_y + g_z);       cnt += g_3 * (g_x * g_y + g_y * g_z + g_x * g_z + num2[g_xy] + num2[g_xz] +                     num2[g_yz]);       cnt += g_3 * ((g_xy + g_yz + g_xz) * (g_x + g_y + g_z));       cnt += g_3 * (g_xy * g_xz + g_xz * g_yz + g_xy * g_yz);       cnt += num2[g_xy] * (g_z + g_xz + g_yz) + num2[g_yz] * (g_x + g_xy + g_xz) +              num2[g_xz] * (g_y + g_xy + g_yz);       cnt += (g_x + g_y + g_z) * (g_xy * g_yz + g_xz * g_yz + g_xy * g_xz);       cnt += (g_x * g_y) * (g_xz + g_yz) + (g_y * g_z) * (g_xy + g_xz) +              (g_x * g_z) * (g_xy + g_yz);       cnt += g_x * g_y * g_z;       cnt += g_xy * g_yz * g_xz;       printf( %d n , (int)cnt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<pair<int, int>, int>> ordered;   deque<pair<int, int>> solutions;   vector<bool> stay, check;   bool cmp(pair<pair<int, int>, int> &a, pair<pair<int, int>, int> &b) {     int A = a.first.second - a.first.first;     int B = b.first.second - b.first.first;     return A < B;   }   vector<pair<pair<int, int>, int>> new_array(       vector<pair<pair<int, int>, int>> &v, int value) {     vector<pair<pair<int, int>, int>> temp;     for (int i = 0; i < v.size(); i++) {       if (stay[i])         temp.push_back(make_pair(             make_pair(v[i].first.first + value, v[i].first.second), v[i].second));     }     return temp;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int aux;       cin >> aux;       stay.push_back(false);       check.push_back(false);       if (i < k)         ordered.push_back(make_pair(make_pair(1, aux), i));       else         solutions.push_back(make_pair(aux, i));     }     sort(ordered.begin(), ordered.end(), cmp);     int d = 0, ans = 0, m = 0;     while (ordered.size() != 0) {       int mini = ordered[0].first.second - ordered[0].first.first + 1;       int index = 0, out = 0, change = 0, intern_ans = 0;       for (auto &x : ordered) {         int L = x.first.first;         int R = L + mini - 1;         int id = x.second;         if (L <= d && d <= R && check[id] == false) {           ans++;           intern_ans++;           check[id] = true;         }         int range = x.first.second - x.first.first + 1;         if (range == mini) {           stay[index++] = false;           m++;           out++;           change = true;         } else           stay[index++] = true;       }       ordered = new_array(ordered, mini);       double temp = 100.00 * ((double)m / n) + 0.5;       d = (int)temp;       while (solutions.size() != 0 && out > 0) {         ordered.push_back(             make_pair(make_pair(1, solutions[0].first), solutions[0].second));         solutions.pop_front();         out--;       }       if (change) sort(ordered.begin(), ordered.end(), cmp);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long funk(long long x, long long y) {     bool used[10000];     long long res = 1;     for (long long i = 1; i <= 100; i++) used[i] = 0;     for (long long i = x + 1; i <= y; i++) {       res *= i;       for (long long j = 2; j <= y - x; j++) {         if (!used[j] && res % j == 0) {           res /= j;           used[j] = 1;         }       }     }     return res;   }   int main() {     long long n, m, t, i, j;     cin >> n >> m >> t;     long long s = 0;     for (i = 4; i < t && i <= n; i++) {       if (t - i <= m) {         s += (funk(i, n) * funk(t - i, m));       }     }     cout << s <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int par[200009];   int flag, sum, ans, cnt, mini, maxi;   int main() {     int n;     scanf( %d , &n);     int a[n];     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     sort(a, a + n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         par[a[i] + a[j]]++;         ans = max(par[a[i] + a[j]], ans);       }     }     cout << ans / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 12;   const int Maxm = 105;   int n, m, k;   string s;   int a[Maxn][Maxm], b[Maxn][Maxm], c[Maxn][Maxm];   int res;   int main() {     scanf( %d %d %d , &n, &m, &k);     getline(cin, s);     for (int i = 0; i < n; i++) {       getline(cin, s);       for (int j = 0; j < m; j++) scanf( %d %d %d , &a[i][j], &b[i][j], &c[i][j]);       getline(cin, s);     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j) {           int cand = 0;           priority_queue<int> Q;           for (int l = 0; l < m; l++)             for (int k = 0; k < c[i][l]; k++) Q.push(b[j][l] - a[i][l]);           for (int l = 0; l < k && !Q.empty() && Q.top() > 0; l++) {             cand += Q.top();             Q.pop();           }           res = max(res, cand);         }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {     return a.first < b.first;   }   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, pair<int, int> > > book;     for (int i = 0; i < n; i++) {       pair<int, pair<int, int> > temp;       cin >> temp.first >> temp.second.first >> temp.second.second;       book.push_back(temp);     }     stack<int> alice, bob, both;     sort(book.begin(), book.end(), comp);     for (int i = 0; i < n; i++) {       int t = book[i].first;       bool a = book[i].second.first;       bool b = book[i].second.second;       if (a && b) {         int t1 = 0, t2 = 0;         if (!alice.empty()) {           t1 = alice.top();         }         if (!bob.empty()) {           t2 = bob.top();         }         if (t1 + t2 >= t) {           both.push(t);           if (alice.size() + both.size() > k) {             alice.pop();           }           if (bob.size() + both.size() > k) {             bob.pop();           }         } else {           if (alice.size() + bob.size() + 2 * both.size() < 2 * k) {             both.push(t);           }           if (alice.size() + both.size() > k) {             alice.pop();           }           if (bob.size() + both.size() > k) {             bob.pop();           }         }       } else if (a) {         if (alice.size() + both.size() < k) {           alice.push(t);         }       } else if (b) {         if (bob.size() + both.size() < k) {           bob.push(t);         }       }     }     if (alice.size() + bob.size() + 2 * both.size() < 2 * k) {       cout << -1 << endl;     } else {       int ans = 0;       while (!alice.empty()) {         ans += alice.top();         alice.pop();       }       while (!bob.empty()) {         ans += bob.top();         bob.pop();       }       while (!both.empty()) {         ans += both.top();         both.pop();       }       cout << ans << endl;     }   }