MOD = 10 ** 9 + 7 from fractions import Fraction n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) cur = 1 inv = {} for i in range(n): cur = (cur * b[i]) % MOD if not b[i] in inv: inv[b[i]] = pow(b[i], MOD - 2, MOD) order = [i for i in range(n)] order.sort(key=lambda i: (b[i] - 1) / a[i]) ans = 0 for i in order: ans = (ans + cur * a[i] * inv[b[i]]) % MOD cur = (cur * inv[b[i]]) % MOD print(ans)