malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int max_n = 1500;   const int max_m = 1500;   const int inv = numeric_limits<int>::max();   int n, m;   char G[max_n][max_m];   int si, sj;   int di[max_n][max_m][4];   int dj[max_n][max_m][4];   int asz[max_n][max_m] = {0};   int vsti[max_n][max_m];   int vstj[max_n][max_m];   stack<int> sti, stj;   int ct[max_n][max_m] = {0};   bool res;   int amod(int p, int d) {     if (p % d < 0)       return p % d + d;     else       return p % d;   }   void DFS() {     int vi, vj;     sti.push(si);     stj.push(sj);     while (!sti.empty()) {       vi = sti.top();       vj = stj.top();       int rvi = amod(vi, n), rvj = amod(vj, m);       vsti[rvi][rvj] = vi;       vstj[rvi][rvj] = vj;       int i;       int ni, nj, rni, rnj;       if (ct[rvi][rvj] == asz[rvi][rvj]) {         sti.pop();         stj.pop();       } else {         i = ct[rvi][rvj];         ++ct[rvi][rvj];         ni = vi + di[rvi][rvj][i];         nj = vj + dj[rvi][rvj][i];         rni = amod(ni, n);         rnj = amod(nj, m);         if (vsti[rni][rnj] == inv) {           sti.push(ni);           stj.push(nj);         } else if (vsti[rni][rnj] != ni or vstj[rni][rnj] != nj) {           res = true;           return;         }       }     }     return;   }   int main() {     int ldi[4] = {-1, 1, 0, 0};     int ldj[4] = {0, 0, -1, 1};     scanf( %d %d , &n, &m);     char trow[max_m + 10];     for (int i = 0; i < n; ++i) {       scanf( %s , trow);       for (int j = 0; j < m; ++j) {         G[i][j] = trow[j];         if (G[i][j] ==  S ) {           G[i][j] =  . ;           si = i;           sj = j;         }       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (G[i][j] ==  . ) {           for (int k = 0; k < 4; ++k) {             int xi = amod(i + ldi[k], n), xj = amod(j + ldj[k], m);             if (G[xi][xj] ==  . ) {               di[i][j][asz[i][j]] = ldi[k];               dj[i][j][asz[i][j]] = ldj[k];               ++asz[i][j];             }           }         }       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         vsti[i][j] = inv;         vstj[i][j] = inv;       }     }     res = false;     DFS();     if (res)       printf( Yes n );     else       printf( No n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void add_self(int &a, int b) {     a += b;     if (a >= (int)1e9 + 7) a -= (int)1e9 + 7;   }   int n, l;   void f(vector<int> &a) {     int x = a[0];     for (int i = 0; i < n - 1; i++) {       a[i] = a[i + 1] - a[i];     }     a[n - 1] = l - a[n - 1] + x;   }   void f1(vector<int> &a, int k) {     reverse(begin(a), end(a));     reverse(begin(a) + k, end(a));     reverse(begin(a), begin(a) + k);   }   void solve() {     cin >> n >> l;     vector<int> a(n), b(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     f(a);     f(b);     for (int i = 0; i < n; i++) {       f1(a, 1);       bool ok = true;       for (int j = 0; j < n; j++) {         if (a[j] != b[j]) {           ok = false;           break;         }       }       if (ok) {         cout <<  YES ;         return;       }     }     cout <<  NO ;   }   int main() {     ios::sync_with_stdio(false);     int q = 1;     for (int i = 1; i <= q; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long int minimum(long long int a[], long long int m, long long int n) {     long long int ar[m];     for (long long int i = 0; i < m; i++) ar[i] = a[i];     long long int j = 0;     long long int ans = 0;     while (n > 0) {       if (ar[j] > 0) {         ans += ar[j];         ar[j] -= 1;         n--;       } else         j++;     }     return ans;   }   long long int maximum(long long int a[], long long int m, long long int n) {     long long int ar[m];     for (long long int i = 0; i < m; i++) ar[i] = a[i];     long long int ans = 0;     long long int j = m - 1;     while (n > 0) {       ans += ar[j];       ar[j] -= 1;       n--;       long long int maxi = ar[j];       long long int id = j;       for (long long int k = m - 1; k >= 0; k--) {         if (maxi < ar[k]) {           id = k;           maxi = ar[k];         }       }       swap(ar[id], ar[j]);     }     return ans;   }   void solve() {     long long int n, m;     cin >> n >> m;     long long int ar[m];     for (auto &it : ar) cin >> it;     ;     sort(ar, ar + m);     long long int mini = minimum(ar, m, n);     long long int maxi = maximum(ar, m, n);     cout << maxi <<     << mini <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long int w, v, qt = 0, n;   inline unsigned long long int f(unsigned long long int x) {     return w * (1 - x) * (1 - x) + v;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> v >> w;     char c;     while (cin >> c) qt += c ==  1 ;     unsigned long long int ans = (~0ULL);     for (int i = 1; i <= qt; i++) {       unsigned long long int tmp = 0;       tmp += (i - (n % i)) * f(n / i);       tmp += (n % i) * f(n / i + 1);       ans = min(ans, tmp);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int number_of_players;     cin >> number_of_players;     int old_bid, counter;     for (counter = 0; counter < number_of_players; counter++) {       int bid;       cin >> bid;       while (bid % 2 == 0) bid /= 2;       while (bid % 3 == 0) bid /= 3;       if (counter == 0)         old_bid = bid;       else if (old_bid != bid) {         cout <<  No  << endl;         break;       }     }     if (counter == number_of_players) cout <<  Yes  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = (long long)1e9 + 7;   long long n, m, k;   const long long moll = 998244353;   long long fact(long long n) {     if (n == 0) return 1;     return (n * fact(n - 1)) % moll;   }   long long binpow(long long a, long long b) {     if (b == 0) return 1;     if (b % 2 == 0) return (binpow((a * a) % moll, b / 2)) % moll;     return (a * (binpow((a * a) % moll, b / 2))) % moll;   }   long long C(long long n, long long k) {     long long x = (fact(n) * binpow(fact(k), moll - 2)) % moll;     x *= binpow(fact(n - k), moll - 2);     x %= moll;     if (x < 0) x += moll;     return x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k;     long long x = m;     x *= C(n - 1, k);     x %= moll;     x *= binpow(m - 1, k);     x %= moll;     if (x < 0) x += moll;     cout << x << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, i, j, a[105], b[105];   int main() {     cin >> n >> m;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < m; i++) cin >> b[i];     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (a[i] == b[j]) {           cout << a[i] <<    ;           b[j] = -1;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> tree[n + 1];     for (int i = 2; i <= n; i++) {       int p;       cin >> p;       tree[p].push_back(i);     }     bool is_spruce = true;     for (int i = 1; i <= n; i++) {       if (tree[i].empty())         continue;       else {         int count = 0;         for (auto c : tree[i]) {           if (count == 3) break;           if (tree[c].size() == 0) count++;         }         if (count != 3) {           is_spruce = false;           break;         }       }     }     if (is_spruce)       cout <<  Yes  << endl;     else       cout <<  No  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long int s, sum = 0;     cin >> n >> s;     long long int* v = new long long int[n];     for (int i = 0; i < n; i++) {       cin >> v[i];       sum += v[i];     }     if (s > sum)       cout << -1 << endl;     else {       sort(v, v + n);       if (s < (sum - v[0] * n))         cout << v[0] << endl;       else {         s -= sum - v[0] * n;         if (s % n == 0)           cout << v[0] - s / n << endl;         else           cout << v[0] - (s / n) - 1 << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   signed long long L[100020], R[100020], T[100020];   signed long long Q[100020];   vector<pair<signed long long, signed long long> > QP;   signed long long PP[200200];   signed long long AS[200200], BS[200200], ret[200200];   vector<signed long long> S[200200], E[200200];   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N >> M;     for (i = 0; i < M; i++) cin >> L[i] >> R[i] >> T[i];     for (i = 0; i < N; i++) cin >> Q[i], QP.push_back(make_pair(Q[i], i));     sort(QP.begin(), QP.end());     map<signed long long, signed long long> UM;     UM[0] = 0;     for (i = 0; i < M; i++) UM[L[i]] = UM[R[i]] = 1;     i = 0;     for (__typeof(UM.begin()) it = UM.begin(); it != UM.end(); it++)       it->second = i++, PP[it->second] = it->first;     for (i = 0; i < M; i++)       S[UM[L[i]]].push_back(T[i]), E[UM[R[i]]].push_back(T[i]);     map<signed long long, int> CS;     for (i = 0; i < UM.size(); i++) {       for (j = 0; j < E[i].size(); j++)         if (--CS[E[i][j]] == 0) CS.erase(E[i][j]);       for (j = 0; j < S[i].size(); j++) CS[S[i][j]]++;       if (CS.size()) {         signed long long ct = CS.begin()->first;         x = lower_bound(QP.begin(), QP.end(), make_pair(ct - PP[i + 1], 0LL)) -             QP.begin();         y = lower_bound(QP.begin(), QP.end(), make_pair(ct - PP[i], 0LL)) -             QP.begin();         AS[x]++;         AS[y]--;         BS[x] -= ct - PP[i + 1], BS[y] += ct - PP[i];       }     }     signed long long aa = 0, bb = 0;     for (i = 0; i < N; i++)       aa += AS[i], bb += BS[i], ret[QP[i].second] = aa * QP[i].first + bb;     for (i = 0; i < N; i++) cout << ret[i] << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false);     for (i = 0; i < argc - 1; i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }
#include <bits/stdc++.h>   int main() {     int q;     std::cin >> q;     while (q--) {       int n;       std::cin >> n;       std::vector<int> a(n);       for (int i = 0; i < n; ++i) {         std::cin >> a[i];       }       for (int i = 0; i < n; i += 2) {         std::cout << -a[i + 1] <<     << a[i] <<    ;       }       std::cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200;   int mn[maxn << 2], lazy[maxn << 2], gs[maxn << 2];   void push(int rt) {     if (lazy[rt] == 1000000000) return;     lazy[rt << 1] = lazy[rt << 1 | 1] = lazy[rt];     mn[rt << 1] = mn[rt << 1 | 1] = lazy[rt];     gs[rt << 1] = gs[rt << 1 | 1] = lazy[rt];     lazy[rt] = 1000000000;   }   void update(int l, int r, int rt, int ql, int qr, int v) {     if (ql <= l && qr >= r)       lazy[rt] = v, mn[rt] = gs[rt] = v;     else {       push(rt);       int mid = l + r >> 1;       if (ql <= mid) update(l, mid, rt << 1, ql, qr, v);       if (qr > mid) update(mid + 1, r, rt << 1 | 1, ql, qr, v);       mn[rt] = min(mn[rt << 1], mn[rt << 1 | 1]);     }   }   int query(int l, int r, int rt, int ql, int qr) {     if (ql <= l && qr >= r) return mn[rt];     push(rt);     int mid = l + r >> 1, ret = 1e9;     if (ql <= mid) ret = query(l, mid, rt << 1, ql, qr);     if (qr > mid) ret = min(ret, query(mid + 1, r, rt << 1 | 1, ql, qr));     return ret;   }   int Pv(int l, int r, int rt, int p) {     if (l == r) return gs[rt];     push(rt);     int mid = l + r >> 1;     if (p <= mid)       return Pv(l, mid, rt << 1, p);     else       return Pv(mid + 1, r, rt << 1 | 1, p);   }   int sum[maxn], a[maxn];   void build(int l, int r, int rt) {     lazy[rt] = 1000000000;     if (l == r)       mn[rt] = gs[rt] = sum[l];     else {       int mid = l + r >> 1;       build(l, mid, rt << 1);       build(mid + 1, r, rt << 1 | 1);       mn[rt] = min(mn[rt << 1], mn[rt << 1 | 1]);     }   }   int vis[maxn];   using pii = pair<int, int>;   pii her[maxn];   vector<int> ans;   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; ++i) cin >> her[i].first >> her[i].second;     for (int i = 1; i <= n; ++i) cin >> a[i];     int pos = -1;     for (int i = 1; i <= n; ++i) {       sum[0] = 0;       sum[n + 1] = 0;       int tp = a[i];       for (int i = 1; i <= n; ++i) vis[i] = 0;       for (int j = 1; j < i; ++j) sum[j] = sum[j - 1] + a[j];       for (int j = n; j > i; --j) sum[j] = sum[j + 1] + a[j];       sum[i] = 0;       build(1, n, 1);       while (true) {         int cnt = 0;         for (int j = 1; j <= m; ++j) {           if (vis[j]) continue;           auto h = her[j];           int S = 0, ps = Pv(1, n, 1, h.first);           if (h.first <= i - 1) S = query(1, n, 1, h.first, i - 1) - ps;           if (h.first >= i + 1) S = query(1, n, 1, i + 1, h.first) - ps;           if (h.second + S >= 0) {             if (h.first <= i - 1) S = Pv(1, n, 1, i - 1) - ps;             if (h.first >= i + 1) S = Pv(1, n, 1, i + 1) - ps;             if (h.second + S + a[i] >= 0) {               a[i] = 0;               vis[j] = 1;               cnt++;               ans.push_back(j);               if (h.first <= i - 1) update(1, n, 1, h.first, i - 1, ps);               if (h.first >= i + 1) update(1, n, 1, i + 1, h.first, ps);             }           }         }         if (!cnt) break;       }       if (ans.size() == m) {         pos = i;         break;       }       a[i] = tp;       ans.clear();     }     cout << pos << endl;     for (auto &u : ans) cout << u <<    ;     puts(  );     return 0;   }
#include <bits/stdc++.h>   const double PI = 3.1415926535897932384626433;   const int KL = 1e5 + 10;   const long long MOD = 1e9 + 7;   using namespace std;   struct point {     long double x, y;     void go(long long x1, long long y1) {       x = x1;       y = y1;     }     void read() { cin >> x >> y; }     point operator-(point b) { return point{x - b.x, y - b.y}; }     point operator+(point b) { return point{x + b.x, y + b.y}; }   };   long double fnd_angle(point p) {     long double len = sqrt(p.x * p.x + p.y * p.y);     long double angle = acos(fabs(p.x) / len);     if (p.y < 0) {       if (p.x >= 0)         angle = 2 * PI - angle;       else         angle += PI;     } else if (p.x < 0)       angle = PI - angle;     return angle;   }   int n, k;   vector<point> A;   vector<pair<long double, long double>> a, b;   multiset<long double> s;   bool ok(long double mid) {     if (k <= 0) return 1;     a.clear();     b.clear();     for (int i = 0; i < n; i++) {       long double dis = sqrt(A[i].x * A[i].x + A[i].y * A[i].y);       if (dis > 2 * mid) continue;       long double angle = fnd_angle(A[i]);       long double angle2 = acos(dis / (2.0 * mid));       a.push_back({angle - angle2, 2 * angle2});       b.push_back({angle + angle2, -2.0 * angle2});     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     reverse(b.begin(), b.end());     int sz = a.size();     for (int i = 0; i < sz; i++) a.push_back({a[i].first + 2 * PI, a[i].second});     for (int i = 0; i < sz; i++) b.push_back({b[i].first - 2 * PI, b[i].second});     int mx = 0;     s.clear();     for (int i = 0; i < a.size(); i++) {       while (s.size() > 0 && *s.begin() < a[i].first) s.erase(s.begin());       if (s.size() + 1 >= k) return 1;       s.insert(a[i].first + a[i].second);     }     s.clear();     for (int i = 0; i < b.size(); i++) {       while (s.size() > 0 && *(--s.end()) > b[i].first) s.erase(--s.end());       if (s.size() + 1 >= k) return 1;       s.insert(b[i].first + b[i].second);     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       point pp;       pp.read();       if (pp.x == 0 && pp.y == 0) {         k--;         continue;       }       A.push_back(pp);     }     n = A.size();     long double lo = 0.0, hi = 2e5;     int cnt = 33;     while (cnt--) {       long double mid = (lo + hi) / 2.0;       if (ok(mid))         hi = mid;       else         lo = mid;     }     cout << fixed << setprecision(8) << lo <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 998244353;   long long int power(long long int x, unsigned long long int y) {     long long res = 1, m = y + 2;     x %= m;     while (y > 0) {       if (y & 1) res = res * x % m;       x = x * x % m;       y >>= 1;     }     return res;   }   long long int modInverse(long long int a, long long int m = MOD) {     return power(a, m - 2);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int n, i, j;       cin >> n;       long long int a[n];       for (i = 0; i < n; i++) cin >> a[i];       long long int p[n + 1];       p[0] = 1;       for (i = 1; i < n + 1; i++) {         p[i] = 100 * p[i - 1] % MOD;       }       long long int dp[n], x = 1;       for (i = 0; i < n; i++) {         dp[i] = x * (100 - a[i]) % MOD;         x *= a[i];         x %= MOD;         dp[i] *= p[n - i - 1];         dp[i] %= MOD;       }       long long int dp1[n];       for (i = 0; i < n; i++) dp1[i] = dp[i] * (i + 1) % MOD;       long long int s1 = n;       for (i = 0; i < n; i++) s1 *= a[i], s1 %= MOD;       long long int s2 = 0;       for (i = 0; i < n; i++) s2 += dp1[i], s2 %= MOD;       long long int s3 = 0;       for (i = 0; i < n; i++) s3 += dp[i], s3 %= MOD;       s3 = p[n] - s3;       while (s3 < 0) s3 += MOD;       s2 += s1;       s2 %= MOD;       cout << s2 * modInverse(s3) % MOD;     }     cerr <<  Time Taken:  << (float)clock() / CLOCKS_PER_SEC * 1000 <<  ms           <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<int> prime(n + 1, 0);     vector<int> div(n + 1, 0);     prime[1] = 1;     for (long long i = 2; i <= n; i++) {       if (!prime[i]) {         for (long long j = i; j <= n; j += i) {           prime[j] = i;         }       }     }     for (int i = 0; i < m; i++) {       int flag;       int x;       char c;       cin >> c >> x;       if (c ==  + ) {         if (div[prime[x]] == x) {           cout <<  Already on  << endl;         } else {           flag = 0;           for (long long i = x; i > 1; i /= prime[i]) {             if (div[prime[i]]) {               flag = div[prime[i]];             }           }           if (flag) {             cout <<  Conflict with   << flag << endl;           } else {             for (long long i = x; i > 1; i /= prime[i]) {               div[prime[i]] = x;             }             if (x == 1) {               div[1] = 1;             }             cout <<  Success  << endl;           }         }       } else {         if (div[prime[x]] != x) {           cout <<  Already off  << endl;         } else {           for (long long i = x; i > 1; i /= prime[i]) {             div[prime[i]] = 0;           }           if (x == 1) {             div[1] = 0;           }           cout <<  Success  << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int query(const vector<int> &S, int v, const vector<int> &T) {     if (S.empty() || T.empty()) return 0;     cout << S.size() <<   n ;     for (int i = 0; i < (int)S.size(); i++)       cout << S[i] + 1 << (i < (int)S.size() - 1 ?     :   n );     cout << T.size() <<   n ;     for (int i = 0; i < (int)T.size(); i++)       cout << T[i] + 1 << (i < (int)T.size() - 1 ?     :   n );     cout << v + 1 <<   n ;     cout << flush;     int answer;     cin >> answer;     return answer;   }   int query(int s, int v, const vector<int> &T) {     return query(vector<int>(1, s), v, T);   }   int N, root;   vector<int> parent;   vector<int> subtree_size;   int main() {     ios::sync_with_stdio(false);     cin >> N;     root = 0;     parent.assign(N, -1);     subtree_size.assign(N, -1);     vector<int> non_root;     for (int i = 0; i < N; i++)       if (i != root) non_root.push_back(i);     for (int i = 0; i < N; i++)       if (i != root) subtree_size[i] = query(root, i, non_root);     subtree_size[root] = N;     vector<int> sorted;     for (int i = 0; i < N; i++) sorted.push_back(i);     sort(sorted.begin(), sorted.end(),          [&](int a, int b) { return subtree_size[a] < subtree_size[b]; });     for (int i = 0; i < N; i++) {       int v = sorted[i];       vector<int> missing_parent;       for (int j = 0; j < i; j++)         if (parent[sorted[j]] < 0) missing_parent.push_back(sorted[j]);       int remaining = query(root, v, missing_parent);       int high = (int)missing_parent.size();       while (remaining > 0) {         int low = 0;         while (low < high) {           int mid = (low + high + 1) / 2;           if (query(root, v,                     vector<int>(missing_parent.begin(),                                 missing_parent.begin() + mid)) == remaining)             high = mid - 1;           else             low = mid;         }         int child = missing_parent[low];         parent[child] = v;         remaining--;       }     }     cout <<  ANSWER  <<   n ;     for (int i = 0; i < N; i++)       if (parent[i] >= 0) cout << i + 1 <<     << parent[i] + 1 <<   n ;     cout << flush;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     if (false) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     }     int n;     cin >> n;     vector<int> v(n + 1, -1);     int xx = 1048576;     long long sum = 0;     for (int i = n; i > 0; i--) {       if (v[i] >= 0) {         continue;       }       while (xx / 2 > i) {         xx /= 2;       }       int a = i ^ (xx - 1);       v[i] = a;       v[a] = i;       sum += (a + i) * 2;     }     if (v[0] < 0) {       v[0] = 0;     }     cout << sum << endl;     for (int i = 0; i <= n; i++) {       if (i > 0) {         cout <<    ;       }       cout << v[i];     }     cout << endl;     if (false) {       fclose(stdin);       fclose(stdout);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 150007;   const double eps = 1e-8;   int n;   double l, r, mid, sm[N], mxp[N], mnp[N];   struct note {     double p, t, c;     int id;   } a[N], b[N];   int cmp(note x, note y) { return x.c > y.c; }   int cmp0(note x, note y) { return x.p < y.p; }   int check() {     double mxv = 0;     for (int i = 1, j, lb, rb; i <= n; i = j) {       j = i;       while (j <= n && a[j].c == a[i].c) ++j;       lb = i, rb = j - 1;       for (int k = i; k < j; ++k) {         mnp[a[k].id] = a[k].p * (1 - mid * sm[rb] / sm[n]);         mxp[a[k].id] = a[k].p * (1 - mid * (sm[lb - 1] + a[k].t) / sm[n]);       }     }     for (int i = 1, j; i <= n; i = j) {       j = i;       while (j <= n && b[j].p == b[i].p) ++j;       for (int k = i; k < j; ++k)         if (mxv > mnp[b[k].id]) return 0;       for (int k = i; k < j; ++k) mxv = max(mxv, mxp[b[k].id]);     }     return 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %lf , &a[i].p), a[i].id = i;     for (int i = 1; i <= n; ++i) scanf( %lf , &a[i].t), a[i].c = a[i].p / a[i].t;     memcpy(b, a, sizeof(a));     sort(b + 1, b + n + 1, cmp0);     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; ++i) sm[i] = sm[i - 1] + a[i].t;     l = 0, r = 1;     while (r - l > eps) {       mid = (l + r) / 2;       if (check())         l = mid;       else         r = mid;     }     printf( %.7lf n , l);     return 0;   }