from itertools import accumulate mod = 10 ** 9 + 7 N = int(input()) A = list(map(int, input().split())) if 0 in A: print(0) exit() use = [0] * (N + 5) lim = 10 ** 9 l = 0 memo = 1 tmp = [] for r, a in enumerate(A): memo *= a while l < r and memo > lim: memo //= A[l] l += 1 use[l] += 1 use[r + 1] -= 1 tmp.append((r + 1, r - l + 1)) use = list(accumulate(use)) for x, y in tmp: use[x] -= y use = list(accumulate(use))[:N] ans = 1 for a, c in zip(A, use): ans *= pow(a, c, mod) ans %= mod print(ans)