#include constexpr int MAX_N = 1205; constexpr int MOD = 1000000007; typedef long long ll; using namespace std; int n; int arr[MAX_N]; ll fact[MAX_N]; ll inv[MAX_N]; ll dp[MAX_N][MAX_N]; int perm(int a, int b) { if (b > a || a < 0 || b < 0) return 0; if (a == b || b == 0) return fact[b]; return (int) ((fact[a] * inv[a-b]) % MOD); } int pow(int b, int p) { if (p == 0) return 1; ll ans = pow(b, p >> 1); ans = (ans * ans) % MOD; if (p & 1) ans = (ans * b) % MOD; return (int) ans; } int main() { scanf(" %d", &n); for (int i = 1; i <= n; i++) { scanf(" %d", &arr[i]); } fact[0] = 1; for (int i = 1; i <= n; i++) { fact[i] = (fact[i-1] * i) % MOD; inv[i] = pow(fact[i], MOD - 2); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { if (j != 1 && arr[i-j+1] > arr[i-j+2]) break; if (i == j) { dp[i][j] = 1; break; } for (int k = j; k <= i; k++) { // if (dp[i-j][k] == 0) break; // printf("adding %d times %d (i = %d, j = %d, k = %d)\n", (int) dp[i-j][k], perm(k, j), i, j, k); dp[i][j] = (dp[i][j] + dp[i-j][k] * perm(k, j)) % MOD; } // printf("dp[%d][%d] = %d\n", i, j, (int) dp[i][j]); } } ll ans = 0; for (int j = 1; j <= n; j++) { ans = (ans + dp[n][j]) % MOD; } printf("%d\n", (int) ans); return 0; }