#include #include using namespace std; constexpr int mod = 1000000007; int fac[1201], inv[1201]; int a[1200]; int dp[1201][1201]; int main() { fac[0] = 1; for(int i = 1; i <= 1200; i++) fac[i] = (long long) fac[i - 1] * i % mod; inv[1200] = 929600184; for(int i = 1200; i >= 1; i--) inv[i - 1] = (long long) inv[i] * i % mod; int n; scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", a + i); fill_n(dp[n], n + 1, 1); for(int i = n - 1; i >= 1; i--) { for(int j = 1; j <= i; j++) { int ans = 0; for(int k = 1; k <= j && i + k <= n; k++) { if(k >= 2 && a[i + k - 2] > a[i + k - 1]) break; ans = ((long long) dp[i + k][k] * fac[j] % mod * inv[j - k] + ans) % mod; } dp[i][j] = ans; } } long long ans = 0; for(int k = 1; k <= n; k++) { if(k >= 2 && a[k - 2] > a[k - 1]) break; ans += dp[k][k]; } printf("%d\n", (int) (ans % mod)); }