#include using namespace std; const int MAXN = 1205; const int MOD = 1000000007; int a[MAXN], dp[MAXN][MAXN], nCr[MAXN][MAXN], fac[MAXN]; void precalc() { for (int i = 0; i < MAXN; i++) nCr[i][0] = 1; for (int i = 1; i < MAXN; i++) { for (int j = 1; j <= MAXN; j++) { nCr[i][j] = (nCr[i-1][j-1] + nCr[i-1][j]) % MOD; } } fac[0] = 1; for (int i = 1; i < MAXN; i++) { fac[i] = (fac[i-1] * 1LL * i) % MOD; } } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", a + i); precalc(); for (int i = 1; i <= n; i++) { if (a[i] < a[i-1]) break; dp[i][i] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { if (dp[i][j] == 0) continue; for (int k = 1; k <= j && i + k <= n; k++) { if (k > 1 && a[i+k] < a[i+k-1]) break; dp[i+k][k] += (((dp[i][j] * 1LL * nCr[j][k]) % MOD) * fac[k]) % MOD; dp[i+k][k] %= MOD; } } } int ans = 0; for (int i = 1; i <= n; i++) { ans += dp[n][i]; ans %= MOD; } printf("%d\n", ans); return 0; }