#include struct Element{ int p; long long value; Element(int p = 0,long long value = 0):p(p), value(value){} }; Element e[100005]; const long long mod = 1e9+7; long long a[100005]; int sum[100005]; long long mul[100005]; long long mMul[100005]; long long power(long long a,long long b){ long long res = 1; while(b){ if(b&1) res = res*a%mod; a = a*a%mod; b /= 2; } return res; } long long inv(long long u){ return power(u,mod-2); } int isBigger(int l,int r){ int valid = r-(l-1); if(valid>=30) return 1; else{ long long cur = 1; for(int i = l; i <= r; i++){ cur *= e[i].value; if(cur>1000000000) return 1; } return 0; } } int getUpper(int p,int n){ int l = p, r = n; int res = -1; while(l<=r){ int m = (l+r)/2; if(isBigger(p,m)==0){ res = m; l = m+1; } else r = m-1; } return res; } int main(){ //printf("%lld\n",1<<30); int n; scanf("%d",&n); sum[0] = 0, mul[0] = 1; int cnt0 = 0; for(int i = 1; i <= n; i++){ scanf("%lld",&a[i]); sum[i] = sum[i-1]; if(a[i]==1) sum[i]++; if(a[i]==0) cnt0++; mul[i] = mul[i-1]*a[i]%mod; } mMul[0] = 1; for(int i = 1; i <= n; i++) mMul[i] = mMul[i-1]*mul[i]%mod; if(cnt0!=0) printf("0\n"); else{ int p = 1, size = 0; while(p<=n){ if(a[p]==1) p++; else{ e[++size] = Element(p,a[p]); p++; } } //for(int i = 1; i <= size; i++) printf("%d %lld\n",e[i].p,e[i].value); long long ans = 1; p = 1; for(int i = 1; i <= n; i++){ while(p<=size && e[p].p