import java.util.*; import java.io.*; import java.math.*; public class Solution { static BufferedReader in; static StringTokenizer stk; static PrintWriter out; static long[][] nPr = new long[1201][1201]; static long MOD = 1000000007L; public static void main(String[] args) throws Exception { out = new PrintWriter(new OutputStreamWriter(System.out)); boolean oj = System.getProperty("TESTING_IN_ECHELON") != null; if (oj) { in = new BufferedReader(new FileReader("src/in.txt")); } else { in = new BufferedReader(new InputStreamReader(System.in)); } // Start of User Code for (int n = 1; n <= 1200; n++) { nPr[n][0] = 1; for (int r = 1; r <= n; r++) { nPr[n][r] = ((n - r + 1) * nPr[n][r - 1]) % MOD; //System.out.println(n + " P " + r + " = " + nPr[n][r]); } } out.println(proc()); // End of User Code out.flush(); in.close(); } static String proc() throws Exception { int n = ni(); int[] m = new int[n + 1]; for (int i = 1; i <= n; i++) { m[i] = ni(); } int[] inc_seq_length = new int[n + 1]; Arrays.fill(inc_seq_length, 1); for (int i = n - 1; i >= 1; i--) { if (m[i + 1] > m[i]) { inc_seq_length[i] = inc_seq_length[i + 1] + 1; } } //System.out.println(Arrays.toString(inc_seq_length)); long[][] dp = new long[n + 1][n + 1]; for (int i = n; i >= 1; i--) { for (int k = 1; k <= inc_seq_length[i]; k++) { if (i + k - 1 == n) { dp[i][k] = 1L; //System.out.println(i + "," + k + " = " + dp[i][k]); } else { int max_ind = min(k, inc_seq_length[i + k]); long temp = 0; for (int t = 1; t <= max_ind; t++) { temp += (nPr[k][t] * dp[i + k][t]) % MOD; } dp[i][k] = temp % MOD; //System.out.println(i + "," + k + " = " + dp[i][k]); } } } long res = 0; for (int t = 1; t <= inc_seq_length[1]; t++) { res += dp[1][t]; } return (res % MOD) + ""; } static long modPow(long n, long pow, long mod) { return BigInteger.valueOf(n).modPow(BigInteger.valueOf(pow), BigInteger.valueOf(mod)).longValue(); } static long modInv(long n, long mod, boolean isPrimeModuli) { if (isPrimeModuli) { return modPow(n, mod - 2, mod); } return BigInteger.valueOf(n).modInverse(BigInteger.valueOf(mod)).longValue(); } // calc factorials static long[] fact; static void calcFactorials(int n) { fact = new long[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) { fact[i] = fact[i - 1] * i; } } static void calcFactorialsModM(int n, long M) { fact = new long[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) { fact[i] = fact[i - 1] * i; fact[i] %= M; } } static long ncr(int n, int r) { return fact[n] / (fact[n - r] * fact[r]); } static long ncrModM(int n, int r, long MOD, boolean isPrimeModuli) { return (((fact[n] * modInv(fact[n - r], MOD, isPrimeModuli)) % MOD) * modInv(fact[r], MOD, isPrimeModuli)) % MOD; } static long toL(String s) { return Long.parseLong(s); } static long toL(BigInteger n) { return n.longValue(); } static int toI(String s) { return Integer.parseInt(s); } static double toD(String s) { return Double.parseDouble(s); } static void printf(String format, Object... args) { out.printf(format, args); } static int ni() throws Exception { while (stk == null || !stk.hasMoreTokens()) { stk = new StringTokenizer(in.readLine()); } return Integer.parseInt(stk.nextToken()); } static long nl() throws Exception { while (stk == null || !stk.hasMoreTokens()) { stk = new StringTokenizer(in.readLine()); } return Long.parseLong(stk.nextToken()); } static double nd() throws Exception { while (stk == null || !stk.hasMoreTokens()) { stk = new StringTokenizer(in.readLine()); } return Double.parseDouble(stk.nextToken()); } static String ns() throws Exception { while (stk == null || !stk.hasMoreTokens()) { stk = new StringTokenizer(in.readLine()); } return stk.nextToken(); } static int min(int a, int b) { return a < b ? a : b; } static int max(int a, int b) { return a > b ? a : b; } static long min(long a, long b) { return a < b ? a : b; } static long max(long a, long b) { return a > b ? a : b; } static int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } }