N=int(input()) A=list(map(int,input().split())) if 0 in A: ans=0 else: l=0 p=1 imos=[0]*(N+2) for r in range(1,N+1): p*=A[r-1] while p>=10**9: p//=A[l] l+=1 imos[l]+=1 imos[r]-=1 imos[r]+=-(r-l) imos[r+1]-=-(r-l) for i in range(1,N+2): imos[i]+=imos[i-1] for i in range(1,N+2): imos[i]+=imos[i-1] mod=10**9+7 ans=1 for i in range(N): ans*=pow(A[i],imos[i],mod) ans%=mod print(ans)