#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int max_n = 1222, mod = 1000000007; int n, a[max_n], dp[max_n][max_n], c[max_n][max_n]; void get_all_c() { c[0][0] = 1; for (int i = 1; i < max_n; ++i) { c[i][0] = 1; for (int j = 1; j <= i; ++j) { c[i][j] = (1LL * c[i][j - 1] * (i - j + 1)) % mod; } } } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); get_all_c(); scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } dp[n][0] = 1; for (int i = n - 1; i >= 0; --i) { for (int j = 1; i + j <= n; ++j) { for (int k = 0; k <= j; ++k) { dp[i][j] += (1LL * dp[i + j][k] * c[j][k]) % mod; dp[i][j] %= mod; } if (a[i + j] < a[i + j - 1]) { break; } } } int ans = 0; for (int i = 0; i <= n; ++i) { ans += dp[0][i]; ans %= mod; } printf("%d\n", ans); return 0; }