#include const int N = 1200 + 10, mod = 1e9 + 7; long dp[N][N], fac[N], inv[N]; long pow_mod(long a, long n) { long r = 1; for (; n; n >>= 1) { if (n & 1) r = 1ll * r * a % mod; a = 1ll * a * a % mod; } return r; } int main() { fac[0] = inv[0] = 1; for (int i = 1; i < N; ++i) { fac[i] = 1ll * i * fac[i - 1] % mod; inv[i] = pow_mod(fac[i], mod - 2); assert(fac[i] * inv[i] % mod == 1); } int n; std::cin >> n; std::vector m(n + 1); std::vector prev(n + 1); for (int i = 1; i <= n; ++i) { std::cin >> m[i]; } prev[0] = -n; prev[1] = 1; for (int i = 2; i <= n; ++i) { if (m[i] > m[i - 1]) prev[i] = prev[i - 1]; else prev[i] = i; } dp[0][n] = 1; for (int i = 0; i < n; ++i) { int u = std::min(i - prev[i] + 1, n); for (int j = 1; j <= u; ++j) { if (!dp[i][j]) continue; for (int k = i + 1; k <= n; ++k) { if (k != i + 1 && m[k] < m[k - 1]) break; if (k - i > j) break; if (i == 0) dp[k][k - i] = 1; else dp[k][k - i] += 1ll * dp[i][j] * fac[j] % mod * inv[j - (k - i)] % mod; dp[k][k - i] %= mod; } } } long ret = 0; for (int i = 1; i <= n; ++i) { ret += dp[n][i]; } ret %= mod; std::cout << ret << std::endl; return 0; }