import java.util.*; import java.io.*; public class Task5 { FastScanner in; PrintWriter out; final long mod = (long) (1e9 + 7); public void solve() throws IOException { int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } long[][] c = new long[n + 1][n + 1]; for (int i = 0; i <= n; i++) c[i][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; } } long[] fact = new long[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) { fact[i] = (fact[i - 1] * i) % mod; } long[][] dp = new long[n + 1][n + 1]; dp[1][1] = 1; for (int i = 1; i < n; i++) { if (a[i] > a[i - 1]) { dp[i + 1][i + 1] = 1; } else { break; } } for (int taken = 1; taken < n; taken++) { for (int last = 1; last <= taken; last++) { int now = 1; do { dp[taken + now][now] = (dp[taken + now][now] + dp[taken][last] * c[last][now] % mod * fact[now]) % mod; now++; } while (taken + now <= n && a[taken + now - 1] > a[taken + now - 2]); } } long ans = 0; for (int i = 1; i <= n; i++) { ans = (ans + dp[n][i]) % mod; } out.println(ans); } public void run() { try { in = new FastScanner(); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static void main(String[] arg) { new Task5().run(); } }