import itertools N = int(input()) A = tuple(map(int, input().split())) MOD = 10 ** 9 + 7 MAX = 10 ** 9 if 0 in A: print(0) exit() lst = [0] * (N + 2) l = 0 tmp = 1 for r in range(N): tmp *= A[r] while tmp >= MAX: tmp //= A[l] l += 1 lst[l] += 1 lst[r + 1] -= r - l + 2 lst[r + 2] += r - l + 1 lst = [x % MOD for x in itertools.accumulate(lst)] lst = [x % MOD for x in itertools.accumulate(lst)] ans = 1 for i in range(N): ans *= pow(A[i], lst[i], MOD) ans %= MOD print(ans)