#include using namespace std; using ll=long long; #define rng(i,a,b) for(int i=int(a);ibool chmax(t&a,u b){ if(abool chmin(t&a,u b){ if(b ostream&operator<<(ostream&os,const pair&p){ return os<<"{"< ostream&operator<<(ostream&os,const vector&v){ os<<"{"; for(auto e:v)os< using vc = vector; #define a first #define b second using P=pair; const ll mod = 1000000007; void add(int &a, int b){ a += b; if(a >= mod) a-=mod; } int n, cnt; vc

pos; int main(){ cin >> n; vcv; rep(i, n){ int a; cin >> a; v.pb(a); } while(v.back() == 1){ cnt ++; v.pop_back(); } reverse(all(v)); while(v.back() == 1){ cnt ++; v.pop_back(); } reverse(all(v)); if(v.empty()){ cout << n << endl; return 0; } ll M = 1, mm = 1; rep(i, v.size()){ if(v[i] > 1) { pos.eb(v[i], i); M = M * v[i]; mm = mm * v[i] % mod; chmin(M, (ll)(1000007)); } } ll ans; if(M >= 1000000){ ans = mm; } else{ int dp[22] = {}; rep(i, pos.size()){ dp[i+1] = 1; for(int j=0;j<=i;j++){ dp[i+1] *= pos[j].a; } } for(int i=1;i<=pos.size();i++){ int add = pos[i].a - pos[i-1].a - 1; int zan = 1; for(int j=i;j