#include #include #include #include using namespace std; typedef long long lint; typedef vectorvi; typedef vectorvl; typedef pairpii; #define rep(i,n)for(int i=0;i<(int)(n);++i) const lint mod=1e9+7; lint cmul(lint a,lint b){ a=min(a,mod); b=min(b,mod); return min(a*b,mod); } int n; vl a; vl o,num,numcap; const lint lim=5e5,blim=19; //WA bool dp[blim+1][lim]; int main(){ cin>>n; a.resize(n); rep(i,n)cin>>a[i]; lint sum=0; int c1=0; lint pr=1,cap=1; int ph=0; rep(i,n){ if(a[i]==1){ if(ph==0){ c1++; }else{ o.push_back(c1); num.push_back(pr); numcap.push_back(cap); ph=0; pr=1; cap=1; c1=1; } }else{ if(ph==0){ ph=1; } pr=pr*a[i]%mod; cap=cmul(cap,a[i]); } } if(ph==0){ sum=c1; }else{ o.push_back(c1); num.push_back(pr); numcap.push_back(cap); } cerr<=lim/2){ sum+=o[0]; cout<<(sum+gpr)%mod<