n = int(input()) a = list(map(int, input().split())) LIMIT = 10 ** 9 MOD = 10 ** 9 + 7 for i in range(n): if a[i] == 0: print(0) exit() # 区間[l, r)を考えつつつ、lとrを尺取りする r = 0 ru_val = 1 ptn_val = 1 ans = 1 for l in range(n): if l > 0: ru_val //= a[l - 1] ptn_val *= pow(pow(a[l - 1], (r - (l - 1)), MOD), MOD - 2, MOD) ptn_val %= MOD while r < n and ru_val * a[r] < LIMIT: ru_val *= a[r] ptn_val *= ru_val ptn_val %= MOD r += 1 ans *= ptn_val ans %= MOD print(ans)