from itertools import permutations N = int(input()) A = [int(a) for a in input().split()] B = [int(a) for a in input().split()] ans = 0 for a in permutations([i for i in range(N)]): s = 0 l = 1 for i in a: s += l * A[i] l *= B[i] ans = max(ans, s) print(ans % (10 ** 9 + 7))