import sys input = sys.stdin.readline N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) mod=10**9+7 X=[(A[i],B[i]) for i in range(N)] X.sort(key=lambda x:(1-x[1])/x[0]) ANS=0 level=1 for a,b in X: ANS+=level*a level*=b ANS%=mod level%=mod print(ANS)