#include using namespace std; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; const ll MOD = 1000000007; const ll INF = 4611686018427387903; #define REP(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() ll power(ll x, ll y) { if (y==0) return 1; else if (y==1) return x%MOD; else if (y%2==0) { ll pow=power(x,y/2); return (pow*pow)%MOD; } else { ll pow=power(x,y/2); return ((pow*pow)%MOD)*x%MOD; } } int main(){ int n; cin >> n; VI a(n); REP(i,n) cin >> a[i]; REP(i,n){ if(a[i]==0){ cout << 0 << endl; return 0; } } vector

b(0); REP(i,n){ if(a[i]!=1) b.push_back({a[i],i}); else if(i==n-1) b.push_back({a[i],i}); } ll ans=1; REP(i,b.size()){ ll p=b[i].second+1; if(i>0) p=b[i].second-b[i-1].second; ll c=b[i].first; ans*=power(c,p); ans%=MOD; for(int j=i+1;j1000000000) break; ans*=power(c,(b[j].second-b[j-1].second)*p); ans%=MOD; } } cout << ans << endl; return 0; }