//package Awesome; import java.awt.Point; import java.io.*; import java.util.*; class TestClass { static long mod ; static boolean F; static String A; public static boolean check(int i , String C, int co){ if(A.length()==i && co==1) return true; long x = Long.parseLong(C)+1; String B = Long.toString(x); if(i+B.length()>A.length()) return false; String D = A.substring(i,i+B.length()); if(D.equals(B)) return check(i+B.length(),B,1); return false; } public static void main(String args[] ) throws java.lang.Exception { InputStream inputStream = System.in; InputReader in = new InputReader(inputStream); //BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\sompatha\\Desktop\\yes.txt")); //Scanner in = new Scanner(new FileReader("C:\\Users\\Sompathak\\Desktop\\yes.txt")); //PrintWriter pw = new PrintWriter(new FileWriter("C:\\Users\\sompatha\\Desktop\\output.txt")); //InputStream inputStream = System.in; //InputReader in = new InputReader(inputStream); //Scanner in = new Scanner(new InputStreamReader(System.in)); //Scanner in = new Scanner(new FileReader("C:\\Users\\sompatha\\Desktop\\yes.txt")); //we can we will ??? !!!!!! SOM RISES //long startTime = System.currentTimeMillis(); //long startTime = System.currentTimeMillis(); //float endTime = System.currentTimeMillis(); //float totalTime = (endTime - startTime)/(float)1000; //System.out.println(totalTime+" sec....."); //System.out.println(check(2,2)+" "+check_2(2,2)); int n = in.nextInt(); int[] A = new int[n+1]; for(int i=1;i<=n;i++) A[i]= in.nextInt(); boolean[][] V = new boolean[n+1][n+1]; for(int i=1;i<=n;i++){ int prev=-1; for(int j=i;j<=n;j++){ if(prev>A[j]) break; prev=A[j]; V[i][j]=true; } } mod = (long) (1e9+7); long ans =0; long[][] dp = new long[n+1][n+1]; long[][] C = new long[1201][1201]; for(int i=1;i<=1200;i++) for(int j=0;j<=i;j++){ if(i==j || j==0) C[i][j]=1; else C[i][j] = C[i-1][j-1] + C[i-1][j]; C[i][j]%=mod; } for(int i=1;i<=n;i++) if(V[1][i]) dp[i][i]=1; long[] Fact = new long[1201]; Fact[0]=1; for(int i=1;i<=1200;i++) Fact[i] = (Fact[i-1]*i)%mod; for(int i=2;i<=n;i++){ for(int j=1;j<=n;j++){ if(i+j-1>n || !V[i][i+j-1]) break; for(int k=j;k<=i;k++){ dp[j][i+j-1]+= dp[k][i-1]*( (C[k][j]*Fact[j])%mod ); dp[j][i+j-1]%=mod; } } } ans=0; for(int i=1;i<=n;i++){ ans+=dp[i][n]; ans%=mod; } System.out.println(ans); }public static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public double readDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }