import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class MergingAlg { static int n, m[]; static int mod = (int) 1e9 + 7; static long fac[]; static void fac() { fac = new long[n + 1]; fac[0] = 1; for(int i = 1; i <= n; i++) fac[i] = (i * fac[i - 1]) % mod; } public static void main(String[] args) throws NumberFormatException, IOException { Scanner sc = new Scanner(); n = sc.nextInt(); m = new int[n]; nPr = new long[n][n]; fac(); for(int i = 0; i < n; i++) m[i] = sc.nextInt(); dp = new long[n][n + 1]; for(int i = 0; i < n; i++) Arrays.fill(dp[i], -1); long ans = solve(0, n); System.out.println(ans); } static long nPr[][]; static long nPr(int n, int r) { if(nPr[n][r] != 0) return nPr[n][r]; return nPr[n][r] = fac[n] * modInv(fac[n -r]) % mod; } static long dp[][]; // 116169488 static long solve(int i, int piles) { if(piles == 0) return 0; if(i == n) return 1; if(dp[i][piles] != -1) return dp[i][piles]; int count = 1; for(int j = i + 1; j < n && count < piles && m[j] > m[j - 1]; j++, count++); // long ans = solve(i, count - 1); // if(i == 0) // ans += solve(i + count, count); // else // ans += solve(i + count, count) * nPr(piles, count) % mod; long ans = 0; for(int p = 1; p <= count; p++) { if(i == 0) ans += solve(i + p, p); else ans += solve(i + p, p) * nPr(piles, p) % mod; ans %= mod; } return dp[i][piles] = ans % mod; } static long modPow(long base, int exp) { long res = 1; while(exp > 0) { if((exp & 1) == 1) { res = res * base % mod; } base = base * base % mod; exp >>= 1; } return res; } static long modInv(long x) { return modPow(x, mod - 2); } static class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; Scanner() { } Scanner(String file) throws FileNotFoundException { br = new BufferedReader(new FileReader(file)); } String next() throws IOException { while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine() throws IOException { return br.readLine(); } int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); } long nextLong() throws NumberFormatException, IOException { return Long.parseLong(next()); } } }