#include #include using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i=0;i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} const ll MOD=1e9+7,MAX=1e9-1; ll power(ll x,ll r){ ll re=1,k=x; for(int i=0;i<60;i++){ if(r>>i&1){ re=(re*k)%MOD; } k=k*k%MOD; } return re; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin>>N; vectorA(N); rep(i,N)cin>>A[i]; rep(i,N){ if(A[i]==0){ cout<<0<<"\n"; return 0; } } vectorL(N); L[0]=0; ll pr=1; rep(i,N){ if(i>0)L[i]=min(N,L[i-1]); while(L[i]S(N+1); rep(i,N){ S[i]--; S[L[i]]++; } rrep(i,N)S[i]+=S[i+1]; rep(i,N)S[i]-=L[i]-i; rrep(i,N)S[i]+=S[i+1]; ll ans=1; rep(i,N)ans=ans*power(A[i],S[i+1])%MOD; cout<