## https://yukicoder.me/problems/no/1084 MOD = 10 ** 9 + 7 def main(): N = int(input()) A = list(map(int, input().split())) for a in A: if a == 0: print(0) return BORDER = 10 ** 9 left = 0 right = 0 ans = A[0] ans1 = A[0] answer = A[0] while left < N: while right < N - 1 and (ans * A[right + 1]) < BORDER: right += 1 ans *= A[right] ans1 *= ans ans1 %= MOD answer *= ans answer %= MOD if right < N - 1: if left < right: v = pow(A[left], (right - left + 1), MOD) v = pow(v, MOD - 2, MOD) ans1 *= v ans1 %= MOD ans //= A[left] left += 1 answer *= ans1 answer %= MOD else: right += 1 left += 1 ans = A[right] ans1 = A[right] answer *= ans answer %= MOD else: if left < right: v = pow(A[left], (right - left + 1), MOD) v = pow(v, MOD - 2, MOD) ans1 *= v ans1 %= MOD ans //= A[left] left += 1 answer *= ans1 answer %= MOD else: break print(answer) if __name__ == "__main__": main()