#include #include #include const int kN = 1200 + 5; const int MOD = (int)1e9 + 7; int a[kN], n; int dp[kN][kN], P[kN], invP[kN]; bool ok[kN][kN]; #define rep(i, a, n) for (int i = (a); i < (n); ++ i) int inv(int x) { return x == 1 ? 1 : (MOD - MOD / x) * 1ll * inv(MOD % x) % MOD; } int main() { scanf("%d", &n); P[0] = invP[0] = 1; for (int i = 1; i < kN; ++ i) P[i] = P[i - 1] * 1ll * i % MOD; for (int i = 1; i < kN; ++ i) invP[i] = inv(P[i]); for (int i = 1; i < kN; ++ i) assert(P[i] * 1ll * invP[i] % MOD == 1); for (int i = 0; i < n; ++ i) { scanf("%d", &a[i]); } for (int i = 0; i < n; ++ i) { for (int j = i; j < n; ++ j) { ok[i][j] = true; if (j + 1 < n && a[j] >= a[j + 1]) break; } } auto add = [](int &a, int b) { a += b; if (a >= MOD) a -= MOD; }; for (int i = 0; i < n; ++ i) { if (ok[0][i]) dp[i + 1][i + 1] = 1; } for (int i = 1; i < n; ++ i) { for (int j = 1; j <= n; ++ j) if (dp[i][j]) { for (int k = 1; k <= j && i + k <= n; ++ k) if (ok[i][i + k - 1]) { add(dp[i + k][k], dp[i][j] * 1ll * P[j] % MOD * invP[j - k] % MOD); } } } int result = 0; for (int i = 0; i <= n; ++ i) add(result, dp[n][i]); printf("%d\n", result); }