#include #include using namespace std; using ll = long long; using mint = atcoder::modint1000000007; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; vector A(N), B(N); for (auto &x : A) cin >> x; for (auto &x : B) cin >> x; vector, ll>> V; // {{分子B, 分母A}, 重み|A|} for (int i = 0; i < N; i++) { if (A[i] == 0) continue; ll a = A[i]; ll b = B[i]; if (a < 0) { a = -a; b = -b; } V.push_back({{b, a}, a}); } sort(V.begin(), V.end(), [](auto x, auto y) { auto [b1, a1] = x.first; auto [b2, a2] = y.first; __int128 left = (__int128)b1 * a2; __int128 right = (__int128)b2 * a1; return left < right; }); ll total = 0; for (auto &e : V) total += e.second; ll cum = 0; pair ans = {0, 1}; for (auto &e : V) { cum += e.second; if (cum * 2 >= total) { ans = e.first; break; } } ll num = ans.first; ll den = ans.second; mint res = mint(num) / mint(den); cout << res.val() << '\n'; return 0; }