import java.io.*; import java.util.*; import java.math.*; class utkarsh { InputStream is; PrintWriter out; long mod=1000000007L; void solve(){ //Enter code here utkarsh int i,j,n,k; long ans; n=ni(); int a[]=na(n); ans=1L; k=n; for(i=0;ia[i]) { if((i-j)>=k)break; i++; } k=i-j; //out.println("k= "+k); ans=(ans*modpow(2,k,mod))%mod; } out.println(ans); } long modpow(long base, long exp, long modulus) { base %= modulus; long result = 1L; while (exp > 0) { if ((exp & 1)==1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result; } public static void main(String[] args) { utkarsh play=new utkarsh(); play.run(); } void run(){ is=System.in; out=new PrintWriter(System.out); solve(); out.flush(); } byte input[]=new byte[1024]; int len=0,ptr=0; int readByte(){ if(ptr>=len){ ptr=0; try{ len=is.read(input); }catch(IOException e){ throw new InputMismatchException(); } if(len<=0){ return -1; } } return input[ptr++]; } boolean isSpaceChar(int c){ return !( c >= 33 && c <= 126 ); } int skip(){ int b=readByte(); while(b!=-1 && isSpaceChar(b)){ b=readByte(); } return b; } char nc(){ return (char)skip(); } String ns(){ int b=skip(); StringBuilder sb=new StringBuilder(); while(!isSpaceChar(b)){ sb.appendCodePoint(b); b=readByte(); } return sb.toString(); } int ni(){ int n=0,b=readByte(); boolean minus=false; while(b!=-1 && !( (b>='0' && b<='9') || b=='-')){ b=readByte(); } if(b=='-'){ minus=true; b=readByte(); } while(b>='0' && b<='9'){ n=n*10 + (b - '0'); b=readByte(); } return minus ? -n : n; } long nl(){ long n=0L; int b=readByte(); boolean minus=false; while(b!=-1 && !( (b>='0' && b<='9') || b=='-')){ b=readByte(); } if(b=='-'){ minus=true; b=readByte(); } while(b>='0' && b<='9'){ n=n*10 + (b - '0'); b=readByte(); } return minus ? -n : n; } double nd(){ return Double.parseDouble(ns()); } float nf(){ return Float.parseFloat(ns()); } int[] na(int n){ int a[]=new int[n]; for(int i=0;i