from fractions import Fraction import sys input = sys.stdin.readline MOD = 10**9+7 N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) M = [] P = [] Z = [] for i in range(N): if A[i]>0: P.append((A[i], B[i])) elif A[i]<0: M.append((A[i], B[i])) else: Z.append((A[i], B[i])) P.sort(key=lambda x:Fraction(x[1], x[0])) M.sort(key=lambda x:Fraction(x[1], x[0])) PA = [0] PB = [0] for a, b in P: PA.append(PA[-1]+a) PB.append(PB[-1]+b) MA = [0] MB = [0] for a, b in M: MA.append(MA[-1]+a) MB.append(MB[-1]+b) SZ = 0 for a, b in Z: SZ += abs(b) INF = 10**18 ans = INF ans2 = INF i = 0 j = 0 while i tmp: ans = tmp ans2 = xp elif ans==tmp and ans2 > xp: ans2 = xp i+=1 else: tmp = SZ tmp += (PB[-1]-PB[i]) - (PA[-1]-PA[i]) * xm tmp += (PA[i] * xm) - PB[i] tmp += MB[j] - MA[j] * xm tmp += (MA[-1]-MA[j]) * xm - (MB[-1]-MB[j]) if ans > tmp: ans = tmp ans2 = xm elif ans==tmp and ans2 > xm: ans2 = xm j+=1 elif i tmp: ans = tmp ans2 = xp elif ans==tmp and ans2 > xp: ans2 = xp i+=1 else: ma, mb = M[j] xm = Fraction(mb, ma) tmp = SZ tmp += (PB[-1]-PB[i]) - (PA[-1]-PA[i]) * xm tmp += (PA[i] * xm) - PB[i] tmp += MB[j] - MA[j] * xm tmp += (MA[-1]-MA[j]) * xm - (MB[-1]-MB[j]) if ans > tmp: ans = tmp ans2 = xm elif ans==tmp and ans2 > xm: ans2 = xm j+=1 ans3 = ans2.numerator * pow(ans2.denominator, MOD-2, MOD) % MOD print(ans3)