#include using namespace std; #define int long long const int MOD = 1e9 + 7; int power(int a, int b){ int res = 1; while(b){ if(b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } int inv(int a){ return power(a, MOD - 2); } signed main() { int n; cin >> n; vector a(n), b(n); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; vector> c; for(int i = 0; i < n; i++){ if(a[i] != 0){ int p = b[i], q = a[i]; if(q < 0){ p = -p; q = -q; } c.push_back({p, q}); } } sort(c.begin(), c.end(), [](pair x, pair y){ return (__int128)x.first * y.second < (__int128)y.first * x.second; }); int total = 0; for(auto &x : c){ total += abs(x.second); } int cur = 0; int p = 0, q = 1; for(auto &x : c){ cur += abs(x.second); if(cur * 2 >= total){ p = x.first; q = x.second; break; } } p = (p % MOD + MOD) % MOD; q = (q % MOD + MOD) % MOD; int ans = p * inv(q) % MOD; cout << ans; }