import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Solution { static int N, sorted[]; static long [][] memo, comb; static long[] fac; static long MOD = (long) 1e9 + 7; static long solve(int i, int have){ if(i == N) return 1; if(memo[i][have] != -1) return memo[i][have]; long ans = 0; for (int j = 1; j <= Math.min(have, sorted[i]); j++) { long t = comb[have][j]; t *= fac[j]; t %= MOD; t *= solve(i + j, j); t %= MOD; ans += t; ans %= MOD; } return memo[i][have] = ans; } static void nCr(int N) { comb = new long[N][N]; comb[0][0] = 1; for (int i = 1; i < N; i++) { comb[i][0] = 1; for (int j = 1; j <= i; j++){ comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]); comb[i][j] %= MOD; } } } static void fac(int N){ fac = new long[N + 1]; fac[1] = 1; for (int i = 2; i <= N; i++) { fac[i] = i * fac[i - 1]; fac[i] %= MOD; } } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); N = sc.nextInt(); nCr(N + 1); fac(N + 1); int[] v = new int[N]; for (int i = 0; i < N; i++) { v[i] = sc.nextInt(); } sorted = new int[N]; sorted[N - 1] = 1; for (int i = N - 2; i >= 0; i--) { if(v[i] < v[i + 1]) sorted[i] = sorted[i + 1] + 1; else sorted[i] = 1; } memo = new long[N][N]; for (int i = 0; i < N; i++) Arrays.fill(memo[i], -1); long ans = 0; for (int i = 1; i <= sorted[0]; i++) { ans += solve(i, i); ans %= MOD; } System.out.println(ans); out.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} } }