#include #define f first #define s second #define mp make_pair #define pb push_back #define lp(i,a,n) for(int i=(a);i<=(int)(n);++i) #define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i) #define mem(a,b) memset(a,b,sizeof a) #define all(v) v.begin(),v.end() #define println(a) cout <<(a) < pii; typedef pair pll; typedef vector vi; typedef vector vvi; typedef vector vll; typedef set si; typedef map mii; const int N = 1202; int n,a[N]; ll dp[N][N],fact[N],revFac[N]; ll power(ll b, ll p) { if(p == 0) return 1; ll sq = power(b, p/2); sq = sq*sq%mod; if(p&1) sq = sq*b%mod; return sq; } void computeFact(){ fact [0] = fact[1] = 1; revFac[0] = revFac[1] = 1; lp(i,1,N-1){ fact[i] = fact[i-1] * i % mod; revFac[i] = power(fact[i], mod-2); } } ll perm(int i, int j){ return fact[i] * revFac[i-j] % mod; } ll solve(int i, int open){ if(i == n+1) return 1; if(dp[i][open] != -1) return dp[i][open]; dp[i][open] = open; lp(j,i+1,n){ if(a[j] < a[j-1] or j-i+1 > open) break; dp[i][open] += solve(j+1, j-i+1) * perm(open, j-i+1) % mod; dp[i][open] %= mod; } return dp[i][open]; } int main(){ computeFact(); readi(n); lp(i,1,n) readi(a[i]); mem(dp,-1); ll ans = 0; lp(i,1,n){ if(a[i] < a[i-1]) break; ans += solve(i+1, i); ans %= mod; } cout <