#include using namespace std; #define F first #define S second #define mp make_pair #define pb push_back #define CLEAR(a) memset(a,0,sizeof a) #define REP(i,n) for(int i=0;i pii; const int MOD = 1e9 + 7; const int MAX = 1500; int N, arr[MAX]; LL dp[MAX][MAX], fac[MAX], inv_fac[MAX]; LL mod_pow(LL base, LL e){ int ret =1; while(e){ if(e%2) ret = (ret*base)%MOD; base = (base*base)%MOD; e /= 2; } return ret; } LL solve(int i, int j){ if(i == N) return 1; if(dp[i][j] != -1) return dp[i][j]; LL ret = 0; FOR(k, 1, j){ if(i+k-1 == N) break; if(k > 1 && arr[i+k-1] < arr[i+k-2]) break; LL tmp = (fac[j]*inv_fac[j-k])%MOD; if(i > 0) ret += (tmp*solve(i+k, k))%MOD; else ret += solve(i+k, k); ret %= MOD; } return dp[i][j] = ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); fac[0] = 1; FOR(i, 1, MAX-1) fac[i] = (fac[i-1]*i)%MOD; REP(i, MAX) inv_fac[i] = mod_pow(fac[i], MOD-2); cin >> N; REP(i, N) cin >> arr[i]; memset(dp,-1,sizeof dp); cout << solve(0, N); return 0; }