import sys input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) mod = 10 ** 9 + 7 if 0 in a: print(0) exit(0) rs = [0] * N r = 0 x = 1 imos = [0] * (N + 1) imosliner = [0] * (N + 1) for l in range(N): while r < N: if x * a[r] >= 10 ** 9: rs[l] = r break x *= a[r] r += 1 else: rs[l] = r x //= a[l] imos[l] += rs[l] - l imosliner[l] -= 1 imosliner[rs[l]] += 1 #print(imos, imosliner) for i in range(N): imos[i + 1] += imos[i] + imosliner[i] imosliner[i + 1] += imosliner[i] res = 1 for i in range(N): res *= pow(a[i], imos[i], mod) res %= mod print(res)