malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, na, nb, nc;   vector<int> a, b;   vector<int> start;   int solve(vector<pair<int, int> > &c, vector<pair<int, int> > &b) {     int nb = b.size();     int nc = c.size();     int ans = 0;     sort(c.begin(), c.end());     sort(b.begin(), b.end());     int i = 0, j = 0;     for (; i < nb && b[i].second; i++)       ;     for (; j < nc && c[j].second; j++)       ;     for (; i < nb && j < nc;) {       int ii = i++, jj = j++;       for (; i < nb && b[i].second; i++)         ;       for (; j < nc && c[j].second; j++)         ;       if (i < nb && j < nc) {         if (ii - i != jj - j) ans++;       }     }     return ans;   }   int main() {     scanf( %d , &n);     b.push_back(0);     for (int i = 0, zz = 0; i < n; i++) {       scanf( %d , &zz);       b.push_back(zz);       for (int j = 0, _x; j < zz; j++) {         scanf( %d , &_x);         a.push_back(_x);       }     }     for (int i = 0; i < n; i++) b[i + 1] += b[i];     int ans = 0;     vector<pair<int, int> > ta, tb;     for (int k = 0; k < n; k++) {       ta.clear();       tb.clear();       for (int i = b[k]; i < b[k + 1]; i++) {         ta.push_back(pair<int, int>(a[i], 0));         tb.push_back(pair<int, int>(a[i], 0));       }       if (k == 0) {         for (int i = b[n - 1]; i < b[n]; i++) {           ta.push_back(pair<int, int>(a[i], 1));         }       } else {         for (int i = b[k - 1]; i < b[k]; i++) {           ta.push_back(pair<int, int>(a[i], 1));         }       }       if (k == n - 2) {         for (int i = b[n - 1]; i < b[n]; i++) {           tb.push_back(pair<int, int>(a[i], 1));         }       } else {         for (int i = b[(k + 1) % n]; i < b[(k + 2) % n]; i++) {           tb.push_back(pair<int, int>(a[i], 1));         }       }       ans += solve(ta, tb);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n, l, r, x;     cin >> n >> l >> r >> x;     long long c[n];     for (long long i = 0; i < n; i++) cin >> c[i];     long long ans = 0;     for (long long i = 0; i < (1 << n); i++) {       long long mn = INT_MAX;       long long mx = 0;       bool ok = true;       long long dif = 0;       for (long long j = 0; j < n; j++) {         if (i & (1 << j)) {           mx = max(mx, c[j]);           mn = min(mn, c[j]);           dif += c[j];         }       }       ans += (dif >= l && dif <= r && mx - mn >= x);     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     if (n & 1)       cout << (n / 2) * (n / 2 + 1);     else       cout << (n / 2) * (n / 2);     cout <<   n ;     for (int i = 1; i <= n / 2; i++)       for (int j = n / 2 + 1; j <= n; j++) cout << i <<     << j <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 234567;   int n;   vector<int> e[N];   int f[N];   void dfs(int u, int p) {     int go_before_parent = 0;     int go_after_parent = 0;     for (int i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (v == p) {         continue;       }       dfs(v, u);       if (f[v] == 0) {         ++go_before_parent;       } else {         ++go_after_parent;       }     }     int son_degree = go_after_parent;     if (son_degree & 1) {       f[u] = 0;     } else {       f[u] = 1;     }   }   void print_solution(int u, int p) {     for (int i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (v == p) {         continue;       }       if (f[v] == 0) {         print_solution(v, u);       }     }     cout << u << endl;     for (int i = 0; i < e[u].size(); ++i) {       int v = e[u][i];       if (v == p) {         continue;       }       if (f[v] == 1) {         print_solution(v, u);       }     }   }   int main() {     cin >> n;     for (int i = 1, j; i <= n; ++i) {       cin >> j;       if (j != 0) {         e[i].push_back(j);         e[j].push_back(i);       }     }     dfs(1, 0);     if (f[1] == 0) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     print_solution(1, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   int x[N], z[2 * N], n, m, k;   struct node {     int v, i;   } y[N];   bool com(node k1, node k2) { return k1.v < k2.v; }   bool f(int w) {     int o = 0, i = 1, j = w, l;     while (i <= n && j <= m) {       if (x[i] <= y[j].v)         z[++o] = x[i], i++;       else         z[++o] = y[j].v, j++;     }     while (i <= n) z[++o] = x[i], i++;     while (j <= m) z[++o] = y[j].v, j++;     for (i = 1, l = 0; i <= o; i += k, l++)       for (j = i; j <= min(o, i + k - 1); j++)         if (z[j] < l) return false;     return true;   }   int main() {     int i, l, r, mid;     scanf( %d%d%d , &n, &m, &k);     for (i = 1; i <= n; i++) scanf( %d , &x[i]);     for (i = 1; i <= m; i++) scanf( %d , &y[i].v), y[i].i = i;     sort(x + 1, x + n + 1);     sort(y + 1, y + m + 1, com);     if (!f(m + 1)) {       puts( -1 );       return 0;     }     l = 0;     r = m + 1;     while (l + 1 < r) {       mid = (l + r) / 2;       if (f(mid))         r = mid;       else         l = mid;     }     printf( %d n , m - r + 1);     for (i = r; i <= m; i++) printf( %d  , y[i].i);   }
#include <bits/stdc++.h>   using namespace std;   const int M = 50 * 1000 * 1000, LG = 40;   int get(long long x, int y) { return (x >> y) & 1; }   int main() {     int n, p;     cin >> n >> p;     for (int i = 0; i < M; i++) {       long long x = (long long)n - 1ll * p * i;       if (x >= i && __builtin_popcount(x) <= i) {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string a;     cin >> a;     int count1 = 0, count2 = 0, count3 = 0, count4 = 0;     for (int i = 0; i < a.length(); i++) {       if (a[i] ==  r  && i % 2 == 0) count1++;       if (a[i] ==  b  && i % 2 == 0) count3++;       if (a[i] ==  b  && i % 2 != 0) count2++;       if (a[i] ==  r  && i % 2 != 0) count4++;     }     cout << min(max(count1, count2), max(count3, count4)) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 2000 * 100 + 100;   vector<pair<int, int> > c[maxN];   bool mark[maxN];   bool used[maxN];   int arr[maxN], ind;   int st[maxN];   struct Ans {     int x, y, z;   };   void dfs(int s) {     mark[s] = true;     st[s] = ind;     arr[ind++] = s;     for (auto x : c[s])       if (!mark[x.first]) dfs(x.first);   }   vector<Ans> ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       c[u].push_back({v, i});       c[v].push_back({u, i});     }     for (int i = 0; i < n; i++)       if (!mark[i]) dfs(i);     reverse(arr, arr + n);     for (int t = 0; t < n; t++) {       int s = arr[t];       sort(c[s].begin(), c[s].end(), [](pair<int, int> a, pair<int, int> b) {         return st[a.first] > st[b.first];       });       pair<int, int> last(-1, -1);       for (auto x : c[s])         if (!used[x.second]) {           if (last.first == -1)             last = x;           else {             ans.push_back({last.first + 1, s + 1, x.first + 1});             used[last.second] = true;             used[x.second] = true;             last = pair<int, int>(-1, -1);           }         }     }     cout << ans.size() <<   n ;     for (auto x : ans) cout << x.x <<     << x.y <<     << x.z <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> dijkstra(vector<vector<int>> &edges, int s) {     vector<int> dist(edges.size(), 1e9);     queue<int> pq;     dist[s] = 0;     pq.push(s);     while (!pq.empty()) {       auto u = pq.front();       pq.pop();       auto d = dist[u];       if (d == dist[u])         for (auto &e : edges[u])           if (dist[e] > d + 1) {             dist[e] = d + 1;             pq.push(e);           }     }     return dist;   }   void print_bees(array<int, 3> &bees) {     for (auto x : bees) cout << 1 + x <<    ;     cout << endl;   }   int read_pos() {     int n;     cin >> n;     return n - 1;   }   bool done(array<int, 3> &bees, int N) {     for (auto x : bees)       if (x == N) return true;     return false;   }   const array<array<int, 3>, 6> perms{{{{0, 1, 2}},                                        {{0, 2, 1}},                                        {{1, 0, 2}},                                        {{1, 2, 0}},                                        {{2, 0, 1}},                                        {{2, 1, 0}}}};   void solve() {     int n, m;     cin >> n >> m;     vector<vector<int>> g(n);     while (m--) {       int u, v;       cin >> u >> v;       --u, --v;       g[u].push_back(v);       g[v].push_back(u);     }     vector<vector<int>> dist(n);     for (int i = 0; i < n; ++i) dist[i] = dijkstra(g, i);     array<int, 3> bees;     for (auto &x : bees) x = rand() % n;     print_bees(bees);     int N;     while (true) {       N = read_pos();       if (done(bees, N)) return;       for (int i = 0; i < 3; ++i) {         if (dist[bees[i]][N] == 1) {           bees[i] = N;           print_bees(bees);           cerr <<  at dist 1 n ;           return;         }       }       vector<int> nbs = g[N];       assert(nbs.size() <= 3);       while (nbs.size() < 3) nbs.push_back(nbs.back());       int best_dist = -1;       array<int, 3> best_bees;       for (auto perm : perms) {         array<int, 3> ps;         for (int i = 0; i < 3; ++i) ps[i] = nbs[perm[i]];         array<int, 3> newbees = bees;         for (int i = 0; i < 3; ++i) {           if (bees[i] == ps[i]) continue;           for (auto d : g[bees[i]])             if (dist[ps[i]][d] < dist[ps[i]][bees[i]]) {               newbees[i] = d;               break;             }         }         int maxdist = 0;         for (int i = 0; i < 3; ++i) maxdist = (maxdist + dist[ps[i]][newbees[i]]);         if (best_dist == -1 or maxdist < best_dist) {           best_dist = maxdist;           best_bees = newbees;         }       }       for (int i = 0; i < 3; ++i) assert(dist[bees[i]][best_bees[i]] <= 1);       bees = best_bees;       print_bees(bees);       if (done(bees, N)) {         cerr <<  this shouldn t happen n ;         return;       }     }   }   int main() {     srand(123245);     solve();   }
#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long b, long long p, long long md) {     if (p == 0) return 1;     if (p % 2 == 1) {       return ((b % md) * bigmod(b, p - 1, md)) % md;     } else {       long long y = bigmod(b, p / 2, md);       return (y * y) % md;     }   }   int cnt[70];   char getchar(int a) {     if (a >= 0 && a <= 9)       return  0  + a;     else if (a >= 10 && a <= 35)       return  a  + a - 10;     else       return  A  + a - 36;   }   int main() {     int n;     cin >> n;     string str;     cin >> str;     for (int i = 0; i < n; i++) {       if (str[i] >=  0  && str[i] <=  9 )         cnt[str[i] -  0 ]++;       else if (str[i] >=  a  && str[i] <=  z )         cnt[str[i] -  a  + 10]++;       else         cnt[str[i] -  A  + 36]++;     }     vector<int> odd;     for (int i = 0; i <= 61; i++) {       if (cnt[i] % 2) {         odd.push_back(i);       }     }     if (odd.size() == 0) {       cout << 1 << endl;       deque<char> dq;       for (int i = 0; i <= 61; i++) {         while (cnt[i]) {           dq.push_back(getchar(i));           dq.push_front(getchar(i));           cnt[i] -= 2;         }       }       for (auto it = dq.begin(); it != dq.end(); it++) cout << *it;       cout << endl;       return 0;     }     int sz = 0;     for (int i = odd.size(); i <= str.size(); i += 2) {       if (str.size() % i) continue;       sz = str.size() / i;       if (sz % 2) break;     }     int total = str.size() / sz;     cout << total << endl;     int c = 0;     while (c != total) {       deque<char> dq;       if (c < odd.size())         dq.push_back(getchar(odd[c])), cnt[odd[c]]--;       else {         for (int i = 0; i <= 61; i++) {           if (cnt[i]) {             dq.push_back(getchar(i));             cnt[i]--;             break;           }         }       }       for (int i = 0; i <= 61; i++) {         while (cnt[i] >= 2 && dq.size() < sz) {           dq.push_back(getchar(i));           dq.push_front(getchar(i));           cnt[i] -= 2;         }       }       for (auto it = dq.begin(); it != dq.end(); it++) cout << *it;       cout <<    ;       c++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   int i, j, k, n, m, res, kilk, cnt;   vector<int> nums;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     if (n < 3) return cout <<  Yes  <<   n , 0;     while (m) {       if (m % n == 0 || m % n == 1)         m /= n;       else {         if (m % n == n - 1)           m = m / n + 1;         else           return cout <<  No  <<   n , 0;       }     }     cout <<  Yes  <<   n ;     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     char in[n];     int result = 0;     scanf( %s , in);     for (int i = 0; i < n; i++) {       if (in[i] ==  < ) {         result++;       } else {         break;       }     }     for (int i = n - 1; i >= 0; i--) {       if (in[i] ==  > ) {         result++;       } else {         break;       }     }     printf( %d n , result);   }
#include <bits/stdc++.h>   using namespace std;   const int len = 3050;   int d[len];   int ans(int n) {     int sum = 0;     while (true) {       int i;       if (!d[0]) break;       for (i = 0; i < n;) {         if (i == n - 1) {           sum++;           break;         }         if (i < n - 2 && d[i + 2])           i += 2;         else if (i < n - 1 && d[i + 1])           i++;         else           return sum;       }       for (i = 0; i < n; i++)         if (d[i] >= 1) d[i]--;     }     return sum;   }   int main() {     int n;     while (~scanf( %d , &n)) {       for (int i = 0; i < n; i++) {         scanf( %d , &d[i]);       }       printf( %d n , ans(n));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void mul(unsigned long long int F[2][2], unsigned long long int M[2][2]) {     unsigned long long int x =         F[0][0] * M[0][0] % 1000000007 + F[0][1] * M[1][0] % 1000000007;     unsigned long long int y =         F[0][0] * M[0][1] % 1000000007 + F[0][1] * M[1][1] % 1000000007;     unsigned long long int z =         F[1][0] * M[0][0] % 1000000007 + F[1][1] * M[1][0] % 1000000007;     unsigned long long int o =         F[1][0] * M[0][1] % 1000000007 + F[1][1] * M[1][1] % 1000000007;     F[0][0] = x % 1000000007;     F[0][1] = y % 1000000007;     F[1][0] = z % 1000000007;     F[1][1] = o % 1000000007;   }   void power(unsigned long long int F[2][2], unsigned long long int n) {     if (n == 0 || n == 1) return;     unsigned long long int N[2][2] = {{3, 1}, {1, 3}};     power(F, n / 2);     mul(F, F);     if (n % 2 != 0) mul(F, N);   }   int main() {     unsigned long long int n, F[2][2] = {{3, 1}, {1, 3}};     cin >> n;     if (n == 0)       cout <<  1  << endl;     else {       power(F, n);       cout << F[0][0] % 1000000007 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int count = 0;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  B  && count > 0) {           count--;         } else {           count++;         }       }       cout << count << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[51][51], n;   int len[2];   bool ok[2][26][51][51];   char str[50][51], s[2][51];   void Init(int id) {     int st, ed, L, mid;     for (int i = 0; i < len[id]; i++) ok[id][s[id][i] -  a ][i + 1][i + 1] = true;     for (L = 2; L <= len[id]; L++)       for (st = 1, ed = st + L - 1; ed <= len[id]; st++, ed++)         for (mid = st; mid < ed; mid++)           for (int i = 0; i < n; i++)             if (ok[id][str[i][3] -  a ][st][mid] &&                 ok[id][str[i][4] -  a ][mid + 1][ed])               ok[id][str[i][0] -  a ][st][ed] = true;   }   int main() {     for (int i = 0; i < 2; i++) {       scanf( %s n , s[i]);       len[i] = strlen(s[i]);     }     scanf( %d n , &n);     for (int i = 0; i < n; i++) scanf( %s n , str[i]);     Init(0);     Init(1);     for (int i = 0; i < 51; i++)       for (int j = 0; j < 51; j++) dp[i][j] = 99999999;     dp[0][0] = 0;     for (int i = 1; i <= len[0]; i++)       for (int j = 1; j <= len[1]; j++)         for (int q = 0; q < i; q++)           for (int p = 0; p < j; p++)             if (dp[q][p] < dp[len[0]][len[1]])               for (int ch = 0; ch < 26; ch++)                 if (ok[0][ch][q + 1][i] && ok[1][ch][p + 1][j]) {                   dp[i][j] = min(dp[q][p] + 1, dp[i][j]);                   break;                 }     if (dp[len[0]][len[1]] < 999999)       printf( %d n , dp[len[0]][len[1]]);     else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<long long>> matrixMul(vector<vector<long long>> lft,                                       vector<vector<long long>> rit,                                       long long mod = 1e9 + 7) {     int n = lft.size(), s = rit.size(), m = rit.back().size();     vector<vector<long long>> res(n, vector<long long>(m, 0));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         for (int k = 0; k < s; ++k)           res[i][j] = (res[i][j] + lft[i][k] * rit[k][j]) % mod;     return res;   }   vector<vector<long long>> matrixPow(vector<vector<long long>> base,                                       long long exp, long long mod = 1e9 + 7) {     int n = base.size();     vector<vector<long long>> res(n, vector<long long>(n, 0));     for (int i = 0; i < n; ++i) res[i][i] = 1;     for (; exp; exp >>= 1, base = matrixMul(base, base, mod))       if (exp & 1) res = matrixMul(res, base, mod);     return res;   }   int main() {     long long n, m;     cin >> n >> m;     vector<vector<long long>> mat;     mat.resize(m);     for (int i = 0; i < m; ++i) mat[i].resize(m);     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j) {         mat[i][j] = 0;       }     for (int i = 1; i < m; ++i) mat[i][i - 1] = 1;     mat[0][0] = 1;     mat[0][m - 1] = 1;     cout << matrixPow(mat, n)[0][0];   }
#include <bits/stdc++.h>   using namespace std;   const int base = 1000 * 1000 * 1000, inf = 1000 * 1000 * 1000;   int buf = 0;   long long gcd(long long a, long long b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   int p[10], e[10][10];   string a[10];   int main() {     int n, k, ans = inf;     cin >> n >> k;     for (int(i) = (1); (i) <= (n); ++(i)) {       cin >> a[i];       for (int(j) = 0; (j) < (a[i].length()); ++(j)) e[i][j + 1] = a[i][j] -  0 ;     }     for (int(i) = (1); (i) <= (k); ++(i)) p[i] = i;     bool ok = true;     for (;;) {       if (!ok) break;       int MAX = -inf, MIN = inf;       for (int(i) = (1); (i) <= (n); ++(i)) {         int w[10];         long long buf = 0;         for (int(j) = (1); (j) <= (k); ++(j)) {           w[j] = e[i][p[j]];           long long y = 1;           for (int(qq) = 0; (qq) < (k - j); ++(qq)) y *= 10;           buf += w[j] * y;         }         if (buf > MAX) MAX = buf;         if (buf < MIN) MIN = buf;       }       if (ans > MAX - MIN) ans = MAX - MIN;       ok = false;       for (int i = k - 1; i >= 1; i--) {         if (p[i] < p[i + 1]) {           int mn = -1;           for (int(j) = (i + 1); (j) <= (k); ++(j))             if (mn == -1 || p[j] > p[i] && p[j] < p[mn]) mn = j;           swap(p[i], p[mn]);           reverse(p + i + 1, p + k + 1);           ok = true;           break;         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   char s[2000], t[2000];   int f[2000];   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     scanf( %s , s + 1);     scanf( %s , t + 1);     for (int i = 1; i <= n - m + 1; i++) {       int flag = 1;       for (int j = 1; j <= m; j++)         if (s[i + j - 1] != t[j]) {           flag = 0;           break;         }       f[i] = f[i - 1] + flag;     }     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       if (r - l + 1 < m)         printf( 0 n );       else         printf( %d n , f[r - m + 1] - f[l - 1]);     }   }
#include <bits/stdc++.h>   const int maxn = 3e5 + 1;   inline long long max(long long a, long long b) { return a > b ? a : b; }   inline long long min(long long a, long long b) { return a < b ? a : b; }   long long rev[19], n, m, opt, k, x, l, r;   struct Segment_Tree {     long long val[maxn << 2];     inline void pushup(long long rt) {       val[rt] = val[rt << 1] + val[rt << 1 | 1];     }     inline void build(long long rt, long long l, long long r) {       if (l == r) return (void)(scanf( %lld , &val[rt]));       build(rt << 1, l, ((l + r) >> 1));       build(rt << 1 | 1, ((l + r) >> 1) + 1, r);       pushup(rt);     }     inline void update(long long rt, long long l, long long r, long long k,                        long long ch, long long dep) {       if (l == r) return (void)(val[rt] = ch);       if (k > ((l + r) >> 1)) {         if (rev[dep])           update(rt << 1, ((l + r) >> 1) + 1, r, k, ch, dep - 1);         else           update(rt << 1 | 1, ((l + r) >> 1) + 1, r, k, ch, dep - 1);       } else {         if (rev[dep])           update(rt << 1 | 1, l, ((l + r) >> 1), k, ch, dep - 1);         else           update(rt << 1, l, ((l + r) >> 1), k, ch, dep - 1);       }       pushup(rt);     }     inline long long query(long long rt, long long l, long long r, long long L,                            long long R, long long dep) {       if (L <= l && r <= R) return val[rt];       long long ans = 0;       if (L <= ((l + r) >> 1)) {         if (rev[dep])           ans += query(rt << 1 | 1, l, ((l + r) >> 1), L, R, dep - 1);         else           ans += query(rt << 1, l, ((l + r) >> 1), L, R, dep - 1);       }       if (R > ((l + r) >> 1)) {         if (rev[dep])           ans += query(rt << 1, ((l + r) >> 1) + 1, r, L, R, dep - 1);         else           ans += query(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R, dep - 1);       }       return ans;     }   } t;   signed main() {     scanf( %lld %lld , &n, &m);     t.build(1, 1, (1ll << n));     for (long long i = 1; i <= m; i++) {       scanf( %lld , &opt);       if (opt == 1)         scanf( %lld %lld , &x, &k), t.update(1, 1, (1ll << n), x, k, n);       if (opt == 2) {         scanf( %lld , &k);         for (long long yny = 0; yny <= k; yny++) rev[yny] ^= 1;       }       if (opt == 3) scanf( %lld , &k), rev[k + 1] ^= 1;       if (opt == 4)         scanf( %lld %lld , &l, &r),             printf( %lld n , t.query(1, 1, (1ll << n), l, r, n));     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 50;   int n, p, first[N], second[N];   double tmin = 1e9;   pair<double, int> d[N];   bool ok(double x) {     double tp = x * p;     for (int i = 0; i < n; ++i) {       tp -= max(first[i] * x - second[i], 0.0);     }     return tp >= 0;   }   int main() {     cin.sync_with_stdio(0);     cin >> n >> p;     for (int i = 0; i < n; ++i) cin >> first[i] >> second[i];     double lo = 0, hi = 1e20, mid;     if (ok(hi)) {       printf( -1 );     } else {       for (int i = 0; i < 1000; ++i) {         mid = (lo + hi) / 2;         if (ok(mid))           lo = mid;         else           hi = mid;       }       printf( %.6f , mid);     }     return 0;   }