malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   mt19937 mrand(43);   const double PI = acos((double)-1);   const double eps = 1e-5;   const long long inf0 = 1023 * 1024 * 1024;   const long long inf = inf0 * inf0;   const long long mod = 1e9 + 7;   void solve();   void scan();   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cout << fixed;     cout.precision(15);     solve();     return 0;   }   const int N = 1e5;   void solve() {     int m;     cin >> m;     vector<int> a;     vector<pair<pair<long long, long long>, pair<long long, long long>>> kek;     long long n = 0;     while (m--) {       int tp;       cin >> tp;       if (tp == 1) {         int x;         cin >> x;         if (a.size() < N)           a.push_back(x);         else           kek.push_back({{n, n}, {-1, x}});         n++;       } else {         long long l, c;         cin >> l >> c;         while (c && a.size() < N) {           for (int i = 0; i < l; i++) {             a.push_back(a[i]);           }           n += l;           c--;         }         if (c) kek.push_back({{n, n + l * c - 1}, {0, l - 1}});         n += l * c;       }     }     int q;     cin >> q;     while (q--) {       long long x;       cin >> x;       x--;       if (x < a.size())         cout << a[x] <<    ;       else {         int h = upper_bound((kek).begin(), (kek).end(),                             make_pair(make_pair(x, (long long)4e18),                                       make_pair(1ll, 1ll))) -                 kek.begin() - 1;         x -= kek[h].first.first;         cout << a[x % (kek[h].second.second + 1)] <<    ;       }     }     return;   }
#include <bits/stdc++.h>   using namespace std;   int al = 1 << 29;   char ans[1000100];   char a[1000100];   int n, m;   void computer(int x, int y) {     int l = 0;     while (x != y) {       if (x > y) {         a[l++] =  T ;         x -= y;       } else {         a[l++] =  B ;         y -= x;       }     }     if (x > 1) return;     a[l++] =  T ;     if (l != n) return;     reverse(a, a + l);     int cur = 0;     int i;     for (i = 1; i < n; i++) {       if (a[i - 1] == a[i]) cur++;     }     if (cur < al) {       al = cur;       for (i = 0; i < n; i++) ans[i] = a[i];     }   }   int main() {     int i;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       computer(i, m);       computer(m, i);     }     if (al >= 1000100)       cout <<  IMPOSSIBLE  << endl;     else {       cout << al << endl;       for (i = 0; i < n; i++) cout << ans[i];       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, s;   int a[110][2];   int main() {     scanf( %d %d , &n, &s);     for (int i = 0; i < n; i++) {       scanf( %d %d , &a[i][0], &a[i][1]);     }     int cnt = 0;     int maxcnt = 0;     int temp = 0;     for (int i = 0; i < n; i++) {       if ((a[i][0] == s && a[i][1] != 0) || a[i][0] > s)         temp++;       else         cnt = 100 - a[i][1];       if (cnt > maxcnt && cnt < 100) {         maxcnt = cnt;       }       cnt = 0;     }     if (temp == n)       printf( -1 n );     else       printf( %d n , maxcnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long inf = 0x3f3f3f3f3f3f3f3f;   const long long mod = 998244353;   const int N = 3e5 + 10;   int n;   int a[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++)       if (a[i] <= a[i - 1] && a[i] <= a[i + 1]) {         puts( NO );         return 0;       }     puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int n, m;   int a[maxn], par[maxn], t[maxn];   vector<int> g[maxn];   int get_par(int v) { return (par[v] == -1) ? v : par[v] = get_par(par[v]); }   void merge(int u, int v) {     u = get_par(u);     v = get_par(v);     if (v == u) return;     par[u] = v;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     cin >> n >> m;     memset(par, -1, sizeof par);     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       merge(u, v);     }     for (int i = 1; i <= n; i++) g[get_par(i)].push_back(a[i]);     for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());     for (int i = 1; i <= n; i++) {       cout << g[get_par(i)].back() <<    ;       g[get_par(i)].pop_back();     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int x, y, n = 0;       cin >> x >> y;       for (int i = 2; i <= x; i++) {         if (x % i == 0) {           n = i;           break;         }       }       cout << x + n + (y - 1) * 2 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int sum = 0;     cin >> n;     int **p;     p = new int *[n];     for (int i = 0; i < n; i++) {       p[i] = new int[n];       for (int j = 0; j < n; j++) {         cin >> p[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j || i + j == n - 1 || i == (n - 1) / 2 || j == (n - 1) / 2) {           sum += p[i][j];         }       }     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   int DEBUG = 1;   using namespace std;   const int N = 100 * 1000 + 5;   const long long INF = 1e17;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long n, k;   long long a, b;   long long x;   long long MIN = +INF;   long long MAX = -INF;   long long dist(long long v, long long u) {     if (v > u) swap(v, u);     return min(u - v, x - (u - v));   }   void check(long long s2) {     long long d = dist(a, s2);     long long L = d;     long long cur = x / gcd(L, x);     MAX = max(MAX, cur);     MIN = min(MIN, cur);   }   int main() {     cin >> n >> k;     cin >> a >> b;     x = n * k;     for (long long e = 0; e < x; e += k) {       check((e - b + x) % x);       check((e + b) % x);     }     cout << MIN <<     << MAX << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int i, j, k, l;     long long n, m, sum;     while (scanf( %lld%lld , &n, &m) != EOF) {       sum = 0;       for (int i = 1; i <= n; i++) {         if (m % i == 0 && m / i <= n) {           ++sum;         }       }       printf( %d n , sum);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> hsh;   int check(string str, int l, int r) {     int pos = 0, cur = 0;     for (int i = r; i >= l; i--) {       if (str[i] ==  ( )         cur++;       else if (str[i] ==  ) )         cur--;       else if (cur == 0 && pos == 0 && (str[i] ==  *  || str[i] ==  / ))         pos = i;       else if (cur == 0 && (str[i] ==  +  || str[i] ==  - )) {         int lft = check(str, l, i - 1), rgt = check(str, i + 1, r);         if (lft == 2 || rgt == 2) return 2;         if (str[i] ==  + )           return 3;         else if (str[i] ==  - ) {           if (rgt == 3)             return 2;           else             return 3;         }       }     }     if (pos) {       int lft = check(str, l, pos - 1), rgt = check(str, pos + 1, r);       if (lft == 2 || rgt == 2) return 2;       if (str[pos] ==  * ) {         if (lft == 3 || rgt == 3)           return 2;         else           return 4;       } else if (str[pos] ==  / ) {         if (lft == 3 || rgt == 3 || rgt == 4)           return 2;         else           return 4;       }     } else if (str[l] ==  (  && str[r] ==  ) ) {       if (check(str, l + 1, r - 1) == 2)         return 2;       else         return 1;     } else {       string res =   ;       for (int i = l; i <= r; i++) res += str[i];       if (hsh[res])         return hsh[res];       else         return 1;     }   }   int main() {     int n;     string s, exp, ques;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       if (s ==  # ) cin >> s;       cin >> s;       getline(cin, exp);       ques =   ;       for (int j = 0; j < exp.length(); j++)         if (exp[j] !=    ) ques += exp[j];       hsh[s] = check(ques, 0, ques.length() - 1);     }     getline(cin, exp);     ques =   ;     for (int i = 0; i < exp.length(); i++)       if (exp[i] !=    ) ques += exp[i];     if (check(ques, 0, ques.length() - 1) == 2)       cout <<  Suspicious  << endl;     else       cout <<  OK  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 9;   const long long INF = 1e12;   int n = 100000;   long long a[MAXN];   long long f[20][MAXN];   void init() {     for (int i = 1; i <= n; i++) {       a[i] = i;     }     for (int i = 1; i <= n; i++) {       for (int j = i + i; j < MAXN; j += i) {         a[j] -= a[i];       }     }   }   long long c(int l, int r) {     long long ans = 0;     int lst = 0;     for (int i = l; i <= r; i = lst + 1) {       lst = r / (r / i);       ans += a[r / i] * (lst - i + 1ll);     }     return ans;   }   void work(long long *dpf, long long *dpg, int l, int r, int L, int R) {     if (l > r) return;     int mid = (l + r) / 2;     int opt = -1;     long long cost = c(min(mid - 1, R) + 1, mid);     for (int i = min(mid - 1, R); i >= L; i--) {       long long newf = dpf[i] + cost;       if (newf < dpg[mid]) {         dpg[mid] = newf;         opt = i;       }       cost += a[mid / i];     }     if (opt == -1) opt = L;     work(dpf, dpg, l, (mid - 1), L, opt);     work(dpf, dpg, (mid + 1), r, opt, R);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     init();     for (int i = 1; i < MAXN; i++) {       a[i] += a[i - 1];     }     f[0][0] = 0;     memset(f, 0x3f, sizeof(f));     for (int i = 1; i <= n; i++) {       f[1][i] = 1ll * i * (i + 1) / 2;     }     for (int i = 1; i < 16; i++) {       work(f[i], f[i + 1], 1, n, 1, n);     }     int T;     cin >> T;     while (T--) {       int n, k;       cin >> n >> k;       if (k >= 17) {         cout << n << endl;       } else {         cout << f[k][n] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, v;   int main() {     n = read();     m = read();     v = read();     if (m > (long long)(n - 1) * (n - 2) / 2 + 1 || m < n - 1) {       printf( -1 n );     } else {       for (int i = 1; i <= n; i++) {         if (i != v) {           printf( %d %d n , v, i);         }       }       int s = (v == 1 ? 2 : 1);       m -= (n - 1);       for (int i = 1; i <= n; i++) {         if (i != s && i != v) {           for (int j = i + 1; j <= n; j++) {             if (j != s && j != v) {               if (!m--) {                 return 0;               }               printf( %d %d n , i, j);             }           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 110;   static int N, M, P, val[MAXN], cut[MAXN];   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++) scanf( %d , &val[i]);     for (int i = 1, odd = 0, evn = 0; i < N; i++) {       ((val[i] & 1) ? odd : evn) += 1;       if (odd == evn) cut[P++] = abs(val[i + 1] - val[i]);     }     sort(cut, cut + P);     for (int i = 0, sum = 0; i < P; i++)       if ((sum += cut[i]) > M) return printf( %d n , i), 0;     printf( %d n , P);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sol1, sol2, sol3, n;   string str;   int main() {     cin >> n >> str;     for (int i = 0; i < str.length(); i++) {       if (str[i] ==  A )         sol1++;       else if (str[i] ==  I )         sol2++;     }     sol3 = str.length() - sol1 - sol2;     if (sol2 == 0) {       cout << sol1 << endl;       return 0;     }     if (sol2 > 1)       cout << 0 << endl;     else       cout << 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ar[6];   int main() {     long long int n, x, j, y, cnt = 0, sum = 0;     for (cin >> n, j = 0; j < n; j++) {       cin >> x >> y;       ar[x] += 1;       ar[y] += 1;     }     for (int i = 1; i <= 5; i++) {       if (ar[i] >= 3 || ar[i] <= 1) cnt++;     }     if (cnt > 0)       cout <<  WIN ;     else       cout <<  FAIL ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int matrix[5][5];     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5; j++) {         cin >> matrix[i][j];       }     }     int row = 0;     int col = 0;     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5; j++) {         if (matrix[i][j] == 1) {           row = i + 1;           col = j + 1;         }       }     }     int swaps = 0;     swaps += abs(3 - row);     swaps += abs(3 - col);     cout << swaps;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);     int m, n;     cin >> m >> n;     vector<int> A(m), B(n);     for (int &i : A) cin >> i;     for (int &i : B) cin >> i;     vector<pair<int, pair<int, int>>> C;     for (int i = 0; i < m; ++i) {       int t;       cin >> t;       for (int j = 0; j < t; ++j) {         int a;         cin >> a;         --a;         C.emplace_back(make_pair(A[i] + B[a], make_pair(i, a)));       }     }     sort(C.rbegin(), C.rend());     long long res = 0;     vector<int> fa(n), fst(m, -1);     iota(fa.begin(), fa.end(), 0);     function<int(int)> ffa = [&](int x) {       if (fa[x] == x) return x;       return fa[x] = ffa(fa[x]);     };     auto merge = [&](int x, int y) {       x = ffa(x);       y = ffa(y);       if (x != y) {         fa[x] = y;       }     };     for (int i = 0; i < ((int)(C).size()); ++i) {       int v = C[i].first;       auto [idx, val] = C[i].second;       if (fst[idx] == -1) {         fst[idx] = val;         continue;       }       if (ffa(fst[idx]) == ffa(val)) {         res += v;       } else {         merge(fst[idx], val);       }     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:167177216 )   using namespace std;   const long long MOD = 1000000000 + 7;   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     long long bcount = 0;     long long ans = 0;     for (int i = s.size() - 1; i >= 0; --i) {       if (s[i] ==  b ) {         bcount++;       }       if (s[i] ==  a ) {         ans += bcount;         bcount *= 2;         bcount %= MOD;         ans %= MOD;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 510;   const int mod = 1e9 + 7;   long long mi1[N], mi[N], C[N][N], dp[N][N];   int main() {     int n, m;     scanf( %d%d , &n, &m);     mi[0] = mi1[0] = 1;     for (int i = 1; i <= n; i++) {       mi[i] = mi[i - 1] * m % mod;       mi1[i] = mi1[i - 1] * (m - 1) % mod;     }     for (int i = 0; i <= n; i++) {       C[i][0] = 1;       for (int j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;     }     for (int j = 1; j <= n; j++) dp[1][j] = C[n][j] * mi1[n - j] % mod;     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= j; k++) {           long long V;           V = (dp[i - 1][k] % mod * C[n - k][j - k] % mod * mi1[n - j] % mod *                mi[k] % mod) %               mod;           dp[i][j] = (dp[i][j] + V) % mod;           if (j == k)             dp[i][j] = (dp[i][j] - mi1[n] * dp[i - 1][k] % mod + mod) % mod;         }       }     }     printf( %lld n , dp[n][n]);   }
#include <bits/stdc++.h>   using namespace std;   char s[1309];   bool a[5201][5201];   int n, i, j, k, f, dp[2][5201][5201];   int main() {     for (scanf( %d , &n), i = 1; i <= n; ++i)       for (scanf( %s , s), j = 0; s[j]; k = s[j] - ( 9  < s[j] ?  A  - 10 :  0 ),                            a[i][(j << 2) + 1] = 8 & k, a[i][(j << 2) + 2] = 4 & k,                            a[i][(j << 2) + 3] = 2 & k, a[i][(j << 2) + 4] = 1 & k,                            ++j)         ;     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; k = (bool)a[i][j],           dp[k][i][j] = 1 + min(dp[k][i - 1][j - 1],                                 min(dp[k][i][j - 1], dp[k][i - 1][j])),           ++j)         ;     for (k = n + 1; --k; f ? (exit(printf( %d n , k) & 0)) : (void)0)       for (f = !(n % (i = k)); f && i <= n; i += k)         for (j = k; f && j <= n; f &= (dp[(bool)a[i][j]][i][j] >= k), j += k)           ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     int m, v, m1, m2, v1, v2;     cin >> a >> b >> c >> d;     m1 = 3 * a / 10;     m2 = a - (a / 250) * c;     if (m1 > m2)       m = m1;     else       m = m2;     v1 = 3 * b / 10;     v2 = b - (b / 250) * d;     if (v1 > v2)       v = v1;     else       v = v2;     if (m > v)       cout <<  Misha ;     else if (m < v)       cout <<  Vasya ;     else       cout <<  Tie ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimise( ofast )   #pragma GCC optimise( unroll-loops )   using namespace std;   const int N = 200000 + 10;   const long long MOD = 1000000000 + 7;   const long long INF = 1000000000000000000;   const long long LOG = 25;   int n, m, k, s1, s2, f, l[N], r[N], val[N], node[N], nodeu[N], NODE[N];   long long dis[N], dis2[N], dis3[N];   vector<pair<int, int>> G[N], Gin[N];   inline void DJ(int v) {     memset(dis, 63, sizeof dis);     dis[v] = 0;     set<pair<long long, int>> st;     st.insert({dis[v], v});     while (st.size()) {       pair<long long, int> fr = *st.begin();       st.erase(st.begin());       for (auto u : G[fr.second]) {         if (dis[u.first] > fr.first + val[u.second]) {           st.erase({dis[u.first], u.first});           dis[u.first] = fr.first + val[u.second];           st.insert({dis[u.first], u.first});         }       }     }   }   inline void DJ2(int v) {     memset(dis2, 63, sizeof dis2);     dis2[v] = 0;     set<pair<long long, int>> st;     st.insert({0, v});     while (st.size()) {       pair<long long, int> fr = *st.begin();       st.erase(st.begin());       for (auto u : G[fr.second]) {         if (dis2[u.first] > fr.first + val[u.second]) {           st.erase({dis2[u.first], u.first});           dis2[u.first] = fr.first + val[u.second];           st.insert({dis2[u.first], u.first});         }       }     }   }   bool cmp(int x, int y) { return dis[node[x]] < dis[node[y]]; }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k >> s1 >> s2 >> f;     for (int i = 1; i <= m; i++) {       int v, u, w;       cin >> v >> u >> w;       G[v].push_back({u, i});       Gin[u].push_back({v, i});       val[i] = w;     }     for (int i = m + 1; i <= m + k; i++) {       int v, u, L, R;       cin >> v >> u >> L >> R;       l[i] = L, r[i] = R;       node[i] = v;       nodeu[i] = u;       G[v].push_back({u, i});       Gin[u].push_back({v, i});       val[i] = R;     }     DJ(s1), DJ2(s2);     for (int i = m + 1; i <= m + k; i++) {       if (dis[node[i]] < dis2[node[i]] && val[i] != l[i]) {         val[i] = l[i];         DJ(s1);         DJ2(s2);         i = m;       }     }     if (dis[f] < dis2[f]) {       cout <<  WIN n ;       for (int i = m + 1; i <= m + k; i++) cout << val[i] <<    ;       return 0;     }     if (dis[f] == dis2[f]) {       cout <<  DRAW n ;       for (int i = m + 1; i <= m + k; i++) cout << val[i] <<    ;       return 0;     }     cout <<  LOSE ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2500 + 10;   int n;   pair<int, int> p[MAXN];   pair<int, int> sec[MAXN];   int sz;   int half(pair<int, int> p) {     assert(p.first || p.second);     return p.second > 0 || (p.second == 0 && p.first < 0);   }   long long dot(pair<int, int> a, pair<int, int> b) {     return 1ll * a.first * b.first + 1ll * a.second * b.second;   }   long long cross(pair<int, int> a, pair<int, int> b) {     return 1ll * a.first * b.second - 1ll * a.second * b.first;   }   int nxt(int x) { return x + 1 == sz ? 0 : x + 1; }   void solve() {     cin >> n;     for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;     long long ans = 0;     for (int i = 0; i < n; i++) {       sz = 0;       for (int j = 0; j < n; j++)         if (i ^ j)           sec[sz++] = {p[j].first - p[i].first, p[j].second - p[i].second};       sort(sec, sec + sz, [](pair<int, int> a, pair<int, int> b) {         return make_tuple(half(a), 0, dot(a, b)) <                make_tuple(half(b), cross(a, b), dot(a, b));       });       long long temp = 0;       int cur = 0;       for (int j = 0; j < sz; j++) {         if (cur == j) cur = nxt(j);         while (cur != j && cross(sec[j], sec[cur]) > 0) cur = nxt(cur);         int ln = cur > j ? cur - j : sz - (j - cur);         temp += 1ll * (ln - 1) * (ln - 2) * (ln - 3) / 6;       }       ans += 1ll * (n - 1) * (n - 2) * (n - 3) * (n - 4) / 24 - temp;     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int te = 1;     for (int w = 1; w <= te; w++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     string s;     cin >> s;     long long int temp = 0;     for (long long int i = 0; i < n - 1; i++) {       if (s[i] > s[i + 1]) {         cout <<  YES  << endl << i + 1 <<     << i + 2 << endl;         temp = 1;         break;       }     }     if (temp == 0) cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 5;   int n, S;   int a[N];   long long now[N];   bool check(int x, int& ans2) {     for (int i = 1; i <= n; i++) {       now[i] = a[i] + 1ll * i * x;     }     sort(now + 1, now + 1 + n);     long long sum = 0;     for (int i = 1; i <= x; i++) {       sum += now[i];       if (sum > S) return false;     }     ans2 = sum;     return true;   }   int main() {     scanf( %d%d , &n, &S);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     int L = 0, R = n, ans1 = 0, ans2 = 0;     while (L <= R) {       int M = L + R >> 1;       if (check(M, ans2)) {         L = M + 1;         ans1 = M;       } else         R = M - 1;     }     printf( %d %d n , ans1, ans2);     return 0;   }
#include <bits/stdc++.h>   struct book {     int t, w;     bool operator<(const book &b) const { return w < b.w; }   } ones[102], twos[102];   int main() {     int n;     scanf( %d , &n);     int nOnes = 0;     int tWidthOnes = 0;     int nTwos = 0;     int tWidthTwos = 0;     for (int i = 0; i < n; i++) {       int t, w;       scanf( %d %d , &t, &w);       if (t == 1) {         ones[nOnes].t = t;         ones[nOnes++].w = w;         tWidthOnes += w;       } else {         twos[nTwos].t = t;         twos[nTwos++].w = w;         tWidthTwos += w;       }     }     std::sort(ones, ones + nOnes);     std::sort(twos, twos + nTwos);     int best = 1 << 30;     for (int i = 1; i <= 1 * nOnes + 2 * nTwos; i++) {       for (int j = 0; j <= i; j++) {         if (j <= nOnes && (i - j) <= nTwos) {           int botWidth = 1 * j + 2 * (i - j);           int topWidth = 0;           for (int k = 0; k < nOnes - j; k++) {             topWidth += ones[k].w;           }           for (int k = 0; k < nTwos - (i - j); k++) {             topWidth += twos[k].w;           }           if (topWidth <= botWidth) {             if (botWidth < best) best = botWidth;           }         }       }     }     printf( %d n , best);   }