#include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int MAXN = 1300; const ll MOD = 1e9 + 7; int N; int arr[MAXN]; ll dp[MAXN][MAXN]; // numways to end up at ind i with j arrays left ll fac[MAXN]; ll ifac[MAXN]; ll cpow (ll b, ll e) { ll ans = 1; ll mpow = b; while (e) { if (e % 2) { ans = (ans * mpow) % MOD; } e /= 2; mpow = (mpow * mpow) % MOD; } return ans; } ll inv (ll x) { return cpow (x, MOD - 2); } int main() { fac[0] = 1; ifac[0] = 1; for (int i = 1; i < MAXN; i++) { fac[i] = (fac[i-1] * i) % MOD; ifac[i] = inv (fac[i]); } cin >> N; for (int i = 0; i < N; i++) cin >> arr[i]; for (int i = 0; i < MAXN; i++) for (int j = 0; j < MAXN; j++) dp[i][j] = 0; for (int i = 0; i < N; i++) { if (i > 0 && arr[i] < arr[i-1]) break; dp[i+1][i+1] = 1; } for (int i = 0; i <= N; i++) { for (int j = 1; j <= N; j++) { //cout << dp[i][j] << " "; if (dp[i][j]) { for (int k = i; k < i + j; k++) { if (k > i && arr[k] < arr[k-1]) break; if (k >= N) break; int len = k - i + 1; dp[k+1][len] = (dp[k+1][len] + dp[i][j] * ((fac[j] * ifac[j-len]) % MOD)) % MOD; } } } //cout << "\n"; } ll ans = 0; for (int i = 0; i <= N; i++) ans = (ans + dp[N][i]) % MOD; cout << ans << "\n"; }