from functools import cmp_to_key def cmp(x, y): a, b = x aa, bb = y s = a*(bb-1) - aa*(b-1) return 1 if s > 0 else -1 if s < 0 else 0 N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) mod = 10**9 + 7 C = [(A[i],B[i]) for i in range(N)] C.sort(key = cmp_to_key(cmp)) x = 1 ans = 0 for a,b in C: ans += a*x ans %= mod x *= b x %= mod print(ans)