#include using namespace std; /////////////////////////////////////////// const long long int INF = 1LL<<60; const long long int Mod = 1000000007; using ll = long long int; using ci = const int; using vi = vector; using Vi = vector; using P = pair; using PLL = pair; using matrix = vector>; #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define rp(i,N) for(ll i = 0; i < (ll)N; i++) #define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i) templatebool chmax(T &former, const T &b) { if (formerbool chmin(T &former, const T &b) { if (bT sqar(T x){ return x*x; }//sqrt(x)は平方根; #define Sort(v) std::sort(v.begin(), v.end(), std::greater()) //降順でVをソート #define p_queue(v) priority_queue, greater > template inline void princ(T x){cout< inline void print(T x){cout< inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } /////////////////////////////////////////////////////////////////////////////////// ll pow(ll x,ll y,ll mod){ if(y==0) return 1; if(y&1) return x*pow(x,y-1,mod)%mod; ll p=pow(x,y/2,mod); return p*p%mod; } void solve(){ int n; cin >> n; Vi a(n); bool z=false; rp(i,n) { cin >> a.at(i); if(a[i]==0) z=true; } if(z) { print(0); return; } ll pre=a[0]; ll l=0,r=0; Vi num(n); while(l1000000000||r==n){ pre/=a[l]; num[l]=r-l; l++; }else{ r++; if(r!=n) pre*=a[r]; } } num[n-1]=1; ll ans=1; ll ctr=0; ll sub=0; p_queue(ll) pos; rp(i,n){ ctr-=sub; ctr+=num[i]; while(pos.size()&&pos.top()==i){ pos.pop(); sub--; } sub++; pos.push(i+num[i]); ans*=pow(a[i],ctr,Mod); ans%=Mod; } print(ans); return; } int main(){ cin.tie(0);ios::sync_with_stdio(false); std::cout<