import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Solution { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); SherlocksArrayMergingAlgorithm solver = new SherlocksArrayMergingAlgorithm(); solver.solve(1, in, out); out.close(); } static class SherlocksArrayMergingAlgorithm { public int mod = 1000000007; public boolean[][] inc; public long[] fact; public long[] ifact; public int n; public long[][] dp; public void solve(int testNumber, InputReader in, OutputWriter out) { n = in.nextInt(); long[][] w = Factorials.getFIF(2 * n, mod); fact = w[0]; ifact = w[1]; int[] arr = in.readIntArray(n); inc = new boolean[n][n]; for (int i = 0; i < n; i++) { inc[i][i] = true; for (int j = i + 1; j < n; j++) { inc[i][j] = inc[i][j - 1] && (arr[j] > arr[j - 1]); } } dp = new long[n][n]; for (long[] x : dp) Arrays.fill(x, -1); long ans = 0; for (int i = 0; i < n && inc[0][i]; i++) { ans = (ans + dfs(i + 1, i + 1)) % mod; } out.println(ans); } public long dfs(int curidx, int lastblock) { if (curidx == n) return 1; if (dp[curidx][lastblock] != -1) return dp[curidx][lastblock]; long ret = 0; for (int next = curidx; next < n && next < curidx + lastblock && inc[curidx][next]; next++) { int cblock = (next - curidx + 1); ret = (ret + fact[lastblock] * ifact[lastblock - cblock] % mod * dfs(next + 1, cblock)) % mod; } return dp[curidx][lastblock] = ret; } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int[] readIntArray(int tokens) { int[] ret = new int[tokens]; for (int i = 0; i < tokens; i++) { ret[i] = nextInt(); } return ret; } public int nextInt() { return Integer.parseInt(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void println(long i) { writer.println(i); } } static class Factorials { public static long[][] getFIF(int max, int mod) { long[] fact = new long[max]; long[] ifact = new long[max]; long[] inv = new long[max]; inv[1] = 1; for (int i = 2; i < max; i++) { inv[i] = (mod - mod / i) * inv[mod % i] % mod; } fact[0] = 1; ifact[0] = 1; for (int i = 1; i < max; i++) { fact[i] = fact[i - 1] * i % mod; ifact[i] = ifact[i - 1] * inv[i] % mod; } return new long[][]{fact, ifact, inv}; } } }