N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) mod = 10**9+7 C = [] for i,v in enumerate(A): tmp = int((B[i]-1)/A[i]*100000) C.append([tmp,i]) C.sort() #print(C) level = 1 ans = 0 for i in range(len(C)-1,-1,-1): tmp1 = C[i][1] ans+=level*A[tmp1] ans%mod level*=B[tmp1] print(ans%mod)