N=int(input()) A=list(map(int,input().split())) C=sum(A) mod=1000000007 J="mada" ans=1 for i in range(N): ans*=A[i] if J=="mada": if ans>=C: J="OK" if J=="OK": ans%=mod if J=="mada": print(C%mod) else: print(ans%mod)