import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { int MOD = 1000000007; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] m = new int[n]; for (int i = 0; i < n; i++) { m[i] = sc.nextInt(); } boolean[][] sorted = new boolean[n][n]; for (int i = 0; i < n; i++) { sorted[i][i] = true; for (int j = i+1; j < n; j++) { if (sorted[i][j-1]&&m[j]>m[j-1]) sorted[i][j] = true; } } long[][] dp = new long[n][n+1]; // ending set, ending length for (int i = 0; i < n; i++) { if (sorted[0][i]) dp[i][i+1]++; } long[][] perm = new long[n+1][n+1]; perm[0][0] = 1; for (int i = 1; i <= n; i++) { perm[i][0] = 1; for (int j = 1; j <= i; j++) { perm[i][j] = (perm[i][j-1]*(i-j+1))%MOD; } } for (int i = 1; i < n; i++) { // beginning for (int j = 1; j <= i; j++) { // length int end = i+j-1; if (end >= n || !sorted[i][end]) continue; for (int k = j; k <= i; k++) { // previous length dp[i+j-1][j] += dp[i-1][k]*perm[k][j]; dp[i+j-1][j] %= MOD; } } } long ans = 0; for (int i = 1; i <= n; i++) { ans += dp[n-1][i]; ans %= MOD; } System.out.println(ans); } }