import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CS2E { static StringTokenizer st; static BufferedReader br; static PrintWriter pw; static class Sort implements Comparable { int ind, a; @Override public int compareTo(Sort o) { return a - o.a; } public Sort(int i, int an) { ind = i; a = an; } } public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); solve(); pw.close(); } static int n; static final long MOD = 1000000007L; static long[] f, fm; static long[][] d; static int[] a; private static void solve() throws IOException { n = nextInt(); f = new long [n + 1]; fm = new long [n + 1]; d = new long [n + 1][n + 1]; a = new int [n]; for (int i = 0; i < n; ++i) a[i] = nextInt(); f[0] = 1; fm[0] = 1; f[1] = 1; fm[1] = 1; for (int i = 2; i <= n; ++i) { f[i] = (f[i - 1] * i) % MOD; fm[i] = pow(f[i], MOD - 2); } d[n][0] = 1; for (int l = n - 1; l >= 0; --l) { for (int h = 1; l + h <= n; ++h) { if (h > 1 && a[l + h - 1] < a[l + h - 2]) break; for (int i = 0; i <= h; ++i) { if (i > 0 && d[l + h][i] == 0) break; d[l][h] = (d[l][h] + fm[h - i] * d[l + h][i]) % MOD; } d[l][h] = d[l][h] * f[h] % MOD; } } long ans = 0; for (int i = 0; i <= n; ++i) { //System.out.println(i + " " + d[0][i]); ans = (ans + d[0][i]) % MOD; } pw.println(ans); } private static long pow(long l, long m) { long ans = 1; while (m > 0) { if (m % 2 == 0) { m /= 2; l = l * l % MOD; } else { ans = ans * l % MOD; m--; } } return ans; } private static int sumf(int[] fen, int id) { int summ = 0; for (; id >= 0; id = (id & (id + 1)) - 1) summ += fen[id]; return summ; } private static void addf(int[] fen, int id) { for (; id < fen.length; id |= id + 1) fen[id]++; } private static int nextInt() throws IOException { return Integer.parseInt(next()); } private static long nextLong() throws IOException { return Long.parseLong(next()); } private static double nextDouble() throws IOException { return Double.parseDouble(next()); } private static String next() throws IOException { while (st==null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } }