#include using namespace std; #define FOR(i,s,e) for (int i=(s); i<(e); i++) #define FOE(i,s,e) for (int i=(s); i<=(e); i++) #define FOD(i,s,e) for (int i=(s); i>=(e); i--) #define EXP(i,l) for (int i=(l); i; i=qn[i]) #define LL long long #define mod 1000000007 LL max(LL a,LL b){if (a>b){return a;} else {return b;}} LL min(LL a,LL b){if (a n) return false; if (sorted[a][b] == -1){ sorted[a][b] = (good(a, b - 1) && (c[b] > c[b - 1])); } return sorted[a][b]; } LL dp[2001][2001]; LL C[2001][2001]; LL con(LL n, LL k){ if (C[n][k] == -1){ C[n][0] = 1; FOE(i, 1, n) C[n][i] = C[n][i - 1] * (n - i + 1) % mod * po(i, mod - 2, mod) % mod; } return C[n][k]; } LL solve(LL a, LL len){ if (len == 1) return 1; if (a == n + 1) return (len == 0); if (len == 0) return 0; if (dp[a][len] == -1){ dp[a][len] = 0; if (good(a, a + len - 1)){ FOE(j, 0, len) if (a + len + j - 1 <= n){ // printf("tran %d %d -> %d %d with %lld\n", a, len, a + len, j, con(len, j)); dp[a][len] = (dp[a][len] + solve(a + len, j) * con(len, j) % mod * fact[j] % mod) % mod; } } // printf("dp[%d][%d] = %lld\n", a, len, dp[a][len]); } return dp[a][len]; } int main() { memset(dp, -1, sizeof(dp)); memset(sorted, -1, sizeof(sorted)); memset(C, -1, sizeof(C)); // printf("%lld\n", con(3, 2)); fact[0] = revfact[0] = 1; FOE(i, 1, 2000) fact[i] = fact[i - 1] * i % mod, revfact[i] = po(fact[i], mod - 2, mod);; scanf("%d", &n); FOE(i, 1, n) scanf("%d", &c[i]); LL ret = 0; FOE(i, 1, n) ret = (ret + solve(1, i)) % mod; printf("%lld\n", ret); return 0; }