from math import gcd from functools import cmp_to_key class Fraction: def __init__(self, top, bottom): GCD = gcd(top, bottom) if bottom < 0: top = -top bottom = -bottom self.top = top//GCD self.bottom = bottom//GCD def to_fraction(n): if type(n) == int: return Fraction(n, 1) else: return n def compare(L, R): L, R = L[0], R[0] L, R = to_fraction(L), to_fraction(R) a = L.top*R.bottom b = L.bottom*R.top if a < b: return -1 elif a == b: return 0 else: return 1 def max_f(L, R): return L if compare(L, R) == 1 else R def min_f(L, R): return L if compare(L, R) == -1 else R def ADD(L, R): L, R = to_fraction(L), to_fraction(R) l, r = L.bottom, R.bottom lt = L.top*r rt = R.top*l top = lt+rt bottom = l*r GCD = gcd(top, bottom) top //= GCD bottom //= GCD if bottom < 0: top = -top bottom = -bottom return Fraction(top, bottom) def SUB(L, R): L, R = to_fraction(L), to_fraction(R) l, r = L.bottom, R.bottom lt = L.top*r rt = R.top*l top = lt-rt bottom = l*r GCD = gcd(top, bottom) top //= GCD bottom //= GCD if bottom < 0: top = -top bottom = -bottom return Fraction(top, bottom) def MUL(L, R): L, R = to_fraction(L), to_fraction(R) top = L.top*R.top bottom = L.bottom*R.bottom GCD = gcd(top, bottom) top //= GCD bottom //= GCD if bottom < 0: top = -top bottom = -bottom return Fraction(top, bottom) def DIV(L, R): L, R = to_fraction(L), to_fraction(R) top = L.top*R.bottom bottom = L.bottom*R.top GCD = gcd(top, bottom) top //= GCD bottom //= GCD if bottom < 0: top = -top bottom = -bottom return Fraction(top, bottom) def inverse(n, d): return n * pow(d, -1, MOD) % MOD MOD = 10**9+7 N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) AB = [] for i in range(N): if A[i] != 0: AB.append((A[i], B[i])) A, B = list(map(list, zip(*AB))) N = len(A) C = [] SUM = 0 for i in range(N): if A[i] == 0: continue if A[i] < 0: A[i] = -A[i] B[i] = -B[i] C.append((Fraction(B[i], A[i]), A[i])) if 1 <= i: SUM += A[i] cmp = cmp_to_key(compare) C.sort(key=cmp) l, r = C[0][1], SUM SUM = 0 pre = C[0][0] X = 0 ans = C[0][0] for a, b in C[1:]: diff = SUB(a, pre) SUM = SUB(SUM, MUL(diff, r)) SUM = ADD(SUM, MUL(diff, l)) if compare((SUM, 0), (X, 0)) == -1: SUM = X ans = a r = SUB(r, b) l = ADD(l, b) pre = a print(inverse(ans.top, ans.bottom))