#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define pb push_back #define mp make_pair #define f first #define s second #define pii pair using namespace std; typedef long long ll; const int N = (int) 2e3 + 10; const int MOD = (int) 1e9 + 7; int n; int a[N]; int dp[N][N]; int cnk[N][N]; int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); //freopen("out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cnk[0][0] = 1; for (int i = 1; i < N; i++) { cnk[i][0] = cnk[i][i] = 1; for (int j = 1; j < i; j++) cnk[i][j] = (cnk[i - 1][j - 1] + cnk[i - 1][j]) % MOD; } cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; reverse(a + 1, a + n + 1); dp[0][0] = 1; for (int i = 1; i <= n; i++) { bool good = 1; for (int j = i; j <= n; j++) { if (j > i) good &= (a[j] < a[j - 1]); if (!good) break; int clen = j - i + 1; int fact = 1; for (int plen = 0; plen <= clen; plen++) { int ank = cnk[clen][plen] * 1ll * fact % MOD; fact = fact * 1ll * (plen + 1) % MOD; dp[j][clen] = (dp[i - 1][plen] * 1ll * ank % MOD + dp[j][clen]) % MOD; } } } //cout<