import sys input=sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) mod=10**9+7 def main(): import bisect N=I() A=LI() ans=1 flag=0 if min(A)==0: print(0) else: ceil=10**9 now=1 temp=1 ans=1 l=0 for r in range(N): now*=A[r] temp=(temp*pow(A[r],r-l+1,mod))%mod while now>=ceil: temp=(temp*pow(now,mod-2,mod)) now=now//A[l] l+=1 ans=(ans*temp)%mod print(ans%mod) main()