from functools import cmp_to_key def cmp(a, b): x, y = a[0], a[1] - 1 xx, yy = b[0], b[1] - 1 s = x * yy - y * xx return 1 if s > 0 else -1 if s < 0 else 0 cmpkey = cmp_to_key(cmp) P = 10 ** 9 + 7 N = int(input()) X = sorted([(int(a), int(b)) for a, b in zip(input().split(), input().split())], key = cmpkey) ans = 0 l = 1 for a, b in X: ans = (ans + l * a) % P l = l * b % P print(ans)