malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, len;   char str[55][25];   long long f[(1 << 20) + 10], bin[55];   double ans[(1 << 20) + 10];   double res;   int main() {     int i, j, k, c;     bin[0] = 1;     for (i = 1; i < 55; i++) bin[i] = (bin[i - 1] << 1);     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %s , str[i]);     len = strlen(str[1]);     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (i != j) {           int same = 0;           for (k = 0; k < len; k++) {             if (str[i][k] == str[j][k]) same |= bin[k];           }           f[same] |= bin[j];         }       }     }     for (i = bin[len] - 1; i >= 0; i--) {       for (j = 0; j < len; j++) {         if (i & bin[j]) {           f[i ^ bin[j]] |= f[i];         }       }     }     ans[0] = 1;     for (i = 0; i < bin[len]; i++) {       for (c = j = 0; j < len; j++) {         if (i & bin[j]) c++;       }       for (j = 0; j < len; j++) {         if (!(i & bin[j])) ans[i | bin[j]] += ans[i] / (len - c);       }       for (j = 0; j < n; j++) {         if (f[i] & bin[j]) res += ans[i];       }     }     printf( %.10f n , res / n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int n, k;     cin >> n >> k;     int a[n + 1];     for (int i = (1); i <= (n); i++) cin >> a[i];     long long int d = 1 + 8 * k;     long long int x = (long long int)floor(((sqrt(d) - 1) / 2));     if (n == 1)       cout << a[1] << endl;     else {       if ((x * (x + 1)) / 2 == k)         cout << a[x] << endl;       else         cout << a[k - (x * (x + 1)) / 2] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check_prime(long long n) {     long long flag = 0;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         flag = 1;         break;       }     }     if (n == 1)       return false;     else if (flag == 0 || n == 2 || n == 3) {       return true;     } else {       return false;     }   }   long long BE(long long x, long long n, long long m) {     long long result = 1;     while (n > 0) {       if (n % 2 == 1) result = result * x % m;       x = x * x % m;       n = n / 2;     }     return result;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     long long n;     cin >> n;     long long x[n], h[n];     long long cnt = 2;     for (long long i = 0; i < n; i++) {       cin >> x[i] >> h[i];     }     for (long long i = 1; i < n - 1; i++) {       if (x[i] - x[i - 1] - 1 >= h[i]) {         cnt++;       } else if (x[i] + h[i] < x[i + 1]) {         cnt++;         x[i] += h[i];       }     }     if (n == 1) {       cout << 1 <<   n ;     } else       cout << cnt <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct data {     int val;     int col;     vector<int> vec;   } arr[100005];   void connect(int a, int b) {     arr[a].vec.push_back(b);     arr[b].vec.push_back(a);   }   int goal[100005];   vector<int> ans;   void dfs(int n, int fl, int flip, int flip1) {     arr[n].col = 1;     if (fl % 2 == 0) {       if (flip % 2 == 0) {         if (arr[n].val != goal[n]) {           if (arr[n].val == 0)             arr[n].val = 1;           else             arr[n].val = 0;           ans.push_back(n);           flip++;         } else {         }       } else {         if (arr[n].val == 0)           arr[n].val = 1;         else           arr[n].val = 0;         if (arr[n].val != goal[n]) {           if (arr[n].val == 0)             arr[n].val = 1;           else             arr[n].val = 0;           ans.push_back(n);           flip++;         }       }     } else {       if (flip1 % 2 == 0) {         if (arr[n].val != goal[n]) {           if (arr[n].val == 0)             arr[n].val = 1;           else             arr[n].val = 0;           ans.push_back(n);           flip1++;         }       } else {         if (arr[n].val == 0)           arr[n].val = 1;         else           arr[n].val = 0;         if (arr[n].val != goal[n]) {           if (arr[n].val == 0)             arr[n].val = 1;           else             arr[n].val = 0;           ans.push_back(n);           flip1++;         }       }     }     fl++;     for (int i = 0; i < arr[n].vec.size(); i++) {       if (arr[arr[n].vec[i]].col == 0) dfs(arr[n].vec[i], fl, flip, flip1);     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int aa, bb;       cin >> aa >> bb;       connect(aa, bb);     }     for (int i = 1; i <= n; i++) {       int v;       cin >> v;       arr[i].val = v;       arr[i].col = 0;     }     for (int i = 1; i <= n; i++) {       cin >> goal[i];     }     dfs(1, 0, 0, 0);     int si = ans.size();     cout << si << endl;     for (int i = 0; i < si; i++) {       cout << ans[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double p, d, t, f, c;     scanf( %lf %lf %lf %lf %lf , &p, &d, &t, &f, &c);     if (p >= d) return puts( 0 ), 0;     double now = t * p, bizo = 0;     while (now <= c) {       double step = now / (d - p);       if (now + p * step >= c) break;       bizo++;       now = now + (p * step) * 2;       now += p * f;       if (now >= c) break;     }     printf( %.0f n , bizo);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool arr[1000][1000];   void change(int n) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         arr[i][j] = !arr[i][j];       }     }   }   int main() {     int n, x, y;     int orig_x;     cin >> n >> x >> y;     orig_x = x;     if (x == 1 && y == 1) {       if (n == 2 || n == 3) {         cout <<  NO  << endl;         return 0;       }       cout <<  YES  << endl;       for (int i = 0; i < n; i++) {         arr[i][(i + 1) % n] = arr[(i + 1) % n][i] = 1;       }       arr[n - 1][0] = arr[0][n - 1] = 0;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           cout << arr[i][j];         }         cout << endl;       }       return 0;     }     if (x == 1 || y == 1) {       if (x + y > n + 1) {         cout <<  NO  << endl;         return 0;       }       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;       return 0;     }     if (x == 1 && y == 1) {       for (int i = 0; i < n; i++) {         arr[i][(i + 1) % n] = 1;         arr[(i + 1) % n][i] = 1;       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           cout << arr[i][j];         }         cout << endl;       }       return 0;     }     int temp1 = min(x, y);     int temp2 = max(x, y);     x = temp1;     y = temp2;     int cycL = n - y + 1;     for (int i = 0; i < cycL; i++) {       arr[i][(i + 1) % cycL] = 1;       arr[(i + 1) % cycL][i] = 1;     }     if (orig_x == 1) change(n);     for (int i = 0; i < n; i++) {       arr[i][i] = 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cout << arr[i][j];       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005];   long long int n, m, k;   long long int judge(long long int x) {     long long int sum = 0;     for (int t = 0; t < x; t++) {       if (a[n - x + t] < b[t]) {         sum = sum + b[t] - a[n - x + t];       }     }     return sum;   }   int main() {     cin >> n >> m >> k;     for (int t = 0; t < n; t++) {       scanf( %d , &a[t]);     }     sort(a, a + n);     for (int t = 0; t < m; t++) {       scanf( %d , &b[t]);     }     sort(b, b + m);     long long int s1 = 0;     long long int left = 0;     long long int right = min(n, m);     while (left <= right) {       long long int mid = (left + right) >> 1;       if (judge(mid) <= k) {         left = mid + 1;         s1 = mid;       } else         right = mid - 1;     }     long long int ans = 0;     for (int t = 0; t < s1; t++) {       ans += b[t];     }     if (ans - k > 0)       ans = ans - k;     else       ans = 0;     printf( %lld %lld n , s1, ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   vector<int> G[N];   vector<pair<int, pair<int, int> > > query;   int color[N], Ecolor[2 * N], f[N], s[2 * N], start[N], finish[N], ans[N];   int n, m, u, v, cnt;   int block_size;   void dfs(int u) {     start[u] = ++cnt;     Ecolor[cnt] = color[u];     for (int i = 0; i < G[u].size(); ++i) {       int v = G[u][i];       if (!start[v]) dfs(v);     }     finish[u] = ++cnt;     Ecolor[cnt] = color[u];   }   bool mo_cmp(pair<int, pair<int, int> > p, pair<int, pair<int, int> > q) {     u = p.second.first, v = q.second.first;     if (start[u] / block_size == start[v] / block_size)       return finish[u] < finish[v];     return start[u] / block_size < start[v] / block_size;   }   void add(int pos) {     f[Ecolor[pos]]++;     s[f[Ecolor[pos]]]++;   }   void rem(int pos) {     s[f[Ecolor[pos]]]--;     f[Ecolor[pos]]--;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     block_size = sqrt(n);     for (int i = 1; i <= n; ++i) cin >> color[i];     for (int i = 1; i < n; ++i) {       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1);     for (int i = 0; i < m; ++i) {       cin >> u >> v;       query.push_back(pair<int, pair<int, int> >(i, pair<int, int>(u, v)));     }     sort(query.begin(), query.end(), mo_cmp);     int curL = 1, curR = 1;     add(1);     for (int i = 0; i < query.size(); ++i) {       int p = query[i].second.first;       while (curL < start[p]) {         rem(curL);         curL++;       }       while (curL > start[p]) {         curL--;         add(curL);       }       while (curR < finish[p]) {         curR++;         add(curR);       }       while (curR > finish[p]) {         rem(curR);         curR--;       }       ans[query[i].first] = s[query[i].second.second * 2];     }     for (int i = 0; i < m; ++i) cout << ans[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     for (int i = 0; i < test; i++) {       int n, k;       cin >> n >> k;       if ((n % 2 != 0 && k % 2 == 0) || k > n)         cout <<  NO  << endl;       else {         if (n % 2 == 0) {           if (k % 2 != 0) {             if (k * 2 > n)               cout <<  NO  << endl;             else {               cout <<  YES  << endl;               for (int j = 0; j < k - 1; j++)                 cout <<  2                       <<    ;               cout << n - (2 * (k - 1)) << endl;             }           } else {             cout <<  YES  << endl;             for (int j = 0; j < k - 1; j++)               cout <<  1                     <<    ;             cout << n - (k - 1) << endl;           }         } else {           cout <<  YES  << endl;           for (int j = 0; j < k - 1; j++)             cout <<  1                   <<    ;           cout << n - (k - 1) << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     if (t <= 203) {       int dp[n * t + 1][301];       memset(dp, 0, sizeof(dp));       int ar[n * t];       int N = n * t;       for (int ctr1 = 0; ctr1 < N; ctr1++) {         if (ctr1 < n)           cin >> ar[ctr1];         else           ar[ctr1] = ar[ctr1 - n];       }       for (int ctr1 = 1; ctr1 <= N; ctr1++) {         for (int ctr2 = 0; ctr2 <= ar[ctr1 - 1]; ctr2++) {           dp[ctr1][ar[ctr1 - 1]] =               max(dp[ctr1][ar[ctr1 - 1]], 1 + dp[ctr1 - 1][ctr2]);         }         for (int ctr2 = 0; ctr2 <= 300; ctr2++)           dp[ctr1][ctr2] = max(dp[ctr1][ctr2], dp[ctr1 - 1][ctr2]);       }       int r = 0;       for (int ctr1 = 0; ctr1 <= 300; ctr1++) r = max(r, dp[N][ctr1]);       cout << r << endl;       return 0;     } else {       int dp[n * 101 + 1][301];       memset(dp, 0, sizeof(dp));       int ar[n * 101];       int N = n * 101;       int poj[301];       memset(poj, 0, sizeof(poj));       for (int ctr1 = 0; ctr1 < N; ctr1++) {         if (ctr1 < n) {           cin >> ar[ctr1];           poj[ar[ctr1]]++;         } else           ar[ctr1] = ar[ctr1 - n];       }       for (int ctr1 = 1; ctr1 <= N; ctr1++) {         for (int ctr2 = 0; ctr2 <= ar[ctr1 - 1]; ctr2++) {           dp[ctr1][ar[ctr1 - 1]] =               max(dp[ctr1][ar[ctr1 - 1]], 1 + dp[ctr1 - 1][ctr2]);         }         for (int ctr2 = 0; ctr2 <= 300; ctr2++)           dp[ctr1][ctr2] = max(dp[ctr1][ctr2], dp[ctr1 - 1][ctr2]);       }       int dp2[n * 101 + 1][301];       memset(dp2, 0, sizeof(dp2));       for (int ctr1 = N - 1; ctr1 >= 0; ctr1--) {         for (int ctr2 = 300; ctr2 >= ar[ctr1]; ctr2--) {           dp2[ctr1][ar[ctr1]] = max(dp2[ctr1][ar[ctr1]], 1 + dp2[ctr1 + 1][ctr2]);         }         for (int ctr2 = 1; ctr2 <= 300; ctr2++)           dp2[ctr1][ctr2] = max(dp2[ctr1][ctr2], dp2[ctr1 + 1][ctr2]);       }       int r = 0;       int nt = t - 202;       for (int ctr1 = 1; ctr1 <= 300; ctr1++)         r = max(r, dp[N][ctr1] + dp2[0][ctr1] + nt * poj[ctr1]);       cout << r << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ans = 0;   string s;   void go(vector<char> k, pair<int, int> start, vector<string> a) {     for (int i = 0; i < s.size(); i++) {       if (s[i] == k[0]) {         start.first--;       }       if (s[i] == k[1]) {         start.first++;       }       if (s[i] == k[2]) {         start.second--;       }       if (s[i] == k[3]) {         start.second++;       }       if (start.first >= n || start.first < 0) {         return;       }       if (start.second >= m || start.second < 0) {         return;       }       if (a[start.first][start.second] ==  # ) {         return;       }       if (a[start.first][start.second] ==  E ) {         ans++;         return;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     pair<int, int> start;     vector<string> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       for (int j = 0; j < m; j++) {         if (a[i][j] ==  S ) {           start.first = i;           start.second = j;         }       }     }     cin >> s;     vector<char> k = { 0 ,  1 ,  2 ,  3 };     do {       go(k, start, a);     } while (next_permutation(k.begin(), k.end()));     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1 << 17;   pair<int, int> v[MAXN];   set<pair<int, int> > ans;   queue<int> Q;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second;       if (v[i].first == 1) Q.push(i);     }     while (!Q.empty()) {       int k = Q.front();       Q.pop();       if (v[k].first == 0) continue;       int id = v[k].second;       v[id].first--, v[id].second ^= k;       ans.insert(make_pair(k, id));       if (v[id].first == 1) Q.push(id);     }     cout << ans.size() << endl;     for (auto it = ans.begin(); it != ans.end(); it++) {       pair<int, int> a = *it;       cout << a.first <<     << a.second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class T>   void print(vector<T>& v, bool spaced = true) {     int n = v.size();     string space = (spaced ?     :   );     for (int i = 0; i < n; ++i) {       cout << v[i] << space;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     string s, t;     cin >> s >> t;     map<char, int> m1;     map<char, int> m2;     for (int i = 0; i < n; ++i) {       m1[s[i]]++;       m2[t[i]]++;     }     for (int i = 0; i < n; ++i) {       if (find((t).begin(), (t).end(), s[i]) == t.end()) {         cout << -1 <<   n ;         return 0;       }     }     for (int i = 0; i < n; ++i) {       if (m1[s[i]] != m2[s[i]]) {         cout << -1 <<   n ;         return 0;       }     }     vector<int> moves;     for (int i = 0; i < n; ++i) {       for (int j = i; j < n; ++j) {         if (t[i] == s[j]) {           for (int k = j - 1; k > i - 1; --k) {             swap(s[k], s[k + 1]);             moves.push_back(k + 1);           }           break;         }       }     }     cout << moves.size() <<   n ;     print(moves);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   map<char, int> mp;   vector<pair<string, int>> lex;   vector<string> lvl[1000001];   int lex_p = -1;   int max_l = 0;   void rec(int l, int cnt) {     if (l > max_l) max_l = l;     lvl[l].push_back(lex[lex_p].first);     for (int i = 0; i < cnt; i++) {       lex_p++;       rec(l + 1, lex[lex_p].second);     }   }   int main() {     string s;     cin >> s;     int lex_cnt = 0;     string cur_lex =   ;     string str =   ;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ,  || i == s.length() - 1) {         lex_cnt++;         if (lex_cnt % 2 == 0) {           int val = 0;           int mn = 1;           for (int j = cur_lex.length() - 1; j >= 0; j--) {             val += (cur_lex[j] -  0 ) * mn;             mn *= 10;           }           lex.push_back(make_pair(str, val));           str =   ;           cur_lex =   ;         } else {           str = cur_lex;           cur_lex =   ;         }       } else         cur_lex += s[i];     }     while (lex_p < int(lex.size()) - 1) {       lex_p++;       rec(0, lex[lex_p].second);     }     cout << max_l + 1 << endl;     for (int i = 0; i < 1000001; i++) {       for (int j = 0; j < lvl[i].size(); j++) cout << lvl[i][j] <<    ;       if (lvl[i].size() > 0) cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int mx = 999999;   int n, k, q;   long long f[6], dp[N];   int main() {     scanf( %d , &k);     for (int i = 0; i < 6; ++i) scanf( %d , &f[i]);     for (int i = 1; i <= mx; ++i) {       int tmp = i, ct = 0;       while (tmp) {         int x = tmp % 10;         if (x % 3 == 0) dp[i] += f[ct] * (x / 3);         ct++;         tmp /= 10;       }     }     for (int i = 0, x = 3; i < 6; ++i, x = x * 10) {       int tmp = min(3 * (k - 1), mx / x);       for (int j = 1; j <= tmp; tmp -= j, j <<= 1)         for (int w = mx; w >= j * x; --w)           dp[w] = max(dp[w], dp[w - j * x] + j * f[i]);       if (tmp) {         for (int w = mx; w >= tmp * x; --w)           dp[w] = max(dp[w], dp[w - tmp * x] + tmp * f[i]);       }     }     scanf( %d , &q);     while (q--) {       int x;       scanf( %d , &x);       printf( %lld n , dp[x]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, lns, t = 0, pos = -1, posl = 0;     string s, ot;     cin >> s;     lns = s.length();     ot.clear();     for (i = 0; i < lns; ++i) {       if (s[i] ==  a )         t++;       else         posl++;     }     if (t == lns) {       cout << s;       return 0;     }     if (posl & 1) {       cout <<  :( ;       return 0;     }     t = 0;     for (i = 0; i < lns; ++i) {       if (s[i] !=  a ) t++;       if (t * 2 > posl) {         pos = i;         break;       }     }     for (i = pos; i < lns; ++i) {       if (s[i] ==  a ) {         cout <<  :( ;         return 0;       }     }     i = 0;     t = pos;     while (i < pos) {       if (s[i] ==  a )         i++;       else if (s[i] != s[t]) {         cout <<  :( ;         return 0;       } else         i++, t++;     }     for (i = 0; i < pos; ++i) {       cout << s[i];     }     cout << ot;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   long long f[155][155][155][2][2], g[155][155][2][2];   void doit() {     scanf( %d %d , &N, &M);     int ans = 0;     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++)         for (int k = j; k <= M; k++) {           f[i][j][k][0][0] = i == 1                                  ? 1                                  : (g[k][k][0][0] - g[j - 1][k][0][0] -                                     g[k][j - 1][0][0] + g[j - 1][j - 1][0][0]) %                                        1000000007;           f[i][j][k][0][1] =               ((g[k][M][0][0] - g[j - 1][M][0][0] - g[k][k + 1 - 1][0][0] +                 g[j - 1][k + 1 - 1][0][0]) %                    1000000007 +                (g[k][M][0][1] - g[j - 1][M][0][1] - g[k][k - 1][0][1] +                 g[j - 1][k - 1][0][1]) %                    1000000007) %               1000000007;           f[i][j][k][1][0] = ((g[j - 1][k][0][0] - g[1 - 1][k][0][0] -                                g[j - 1][j - 1][0][0] + g[1 - 1][j - 1][0][0]) %                                   1000000007 +                               (g[j][k][1][0] - g[1 - 1][k][1][0] -                                g[j][j - 1][1][0] + g[1 - 1][j - 1][1][0]) %                                   1000000007) %                              1000000007;           f[i][j][k][1][1] =               ((g[j - 1][M][0][0] - g[1 - 1][M][0][0] -                 g[j - 1][k + 1 - 1][0][0] + g[1 - 1][k + 1 - 1][0][0]) %                    1000000007 +                (g[j - 1][M][0][1] - g[1 - 1][M][0][1] - g[j - 1][k - 1][0][1] +                 g[1 - 1][k - 1][0][1]) %                    1000000007 +                (g[j][M][1][0] - g[1 - 1][M][1][0] - g[j][k + 1 - 1][1][0] +                 g[1 - 1][k + 1 - 1][1][0]) %                    1000000007 +                (g[j][M][1][1] - g[1 - 1][M][1][1] - g[j][k - 1][1][1] +                 g[1 - 1][k - 1][1][1]) %                    1000000007) %               1000000007;         }       for (int j = 1; j <= M; j++)         for (int k = 1; k <= M; k++)           for (int x = 0; x < 4; x++)             g[j][k][x / 2][x & 1] =                 (f[i][j][k][x / 2][x & 1] + g[j - 1][k][x / 2][x & 1] +                  g[j][k - 1][x / 2][x & 1] - g[j - 1][k - 1][x / 2][x & 1]) %                 1000000007;       for (int x = 0; x < 4; x++)         (ans += g[M][M][x / 2][x & 1] * (N - i + 1) % 1000000007) %= 1000000007;     }     cout << (ans + 1000000007) % 1000000007 << endl;   }   int main() {     doit();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct camel {     int pos;     int tof;   };   int main() {     cout << setprecision(8) << fixed;     double l, d, v, g, r;     cin >> l >> d >> v >> g >> r;     double temp;     double T;     temp = d / v;     double q;     bool yer = 1;     while (temp >= 0) {       if (yer) {         temp -= g;         T = 0;         yer = !yer;       } else {         T = r - temp;         temp -= r;         yer = !yer;       }     }     cout << ((l / v) + T);   }
#include <bits/stdc++.h>   using namespace std;   const long long o = 1e4 + 1;   long long n, m, q, a[o], b[o];   long long qwq(long long x) {     long long s = 0;     for (long long i = 1; i <= n; i++) {       if (1.0 * x * a[i] > b[i] * (m + 100)) return m + 1000;       s += 1 + x * a[i] / b[i];     }     return s;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     bool q = 1;     long long x, y;     for (long long i = 1; i <= n; i++) cin >> a[i] >> b[i], q &= !a[i];     if (q) return cout << (n == m ? -1 : 0), 0;     long long l = 1, r = 1e18;     while (l < r) {       long long mid = (l + r + 1) >> 1;       if (qwq(mid) > m)         r = mid - 1;       else         l = mid;     }     if (qwq(l) != m) return cout << 0, 0;     x = l, l = 1, r = 1e18;     while (l < r) {       long long mid = (l + r) >> 1;       if (qwq(mid) < m)         l = mid + 1;       else         r = mid;     }     y = l;     cout << max(0ll, x - y + 1);     return 0;   }