#define FOR(i,n) for (ll i=0; i<(n); ++i) #define FORU(i,l,r) for (ll i=(l); i<=(r); ++i) #define FORD(i,l,r) for (ll i=(r); i>=(l); --i) #include #include #include #include #include using namespace std; typedef vector vi; typedef long long ll; const int MOD=1000000007; ll powmod(ll a, ll k) { ll res=1; while (k) { if (k & 1) { res *= a; res %= MOD; } a *= a; a %= MOD; k >>= 1; } return res; } ll inv(ll a) { return powmod(a,MOD-2); } const int MAX=1207; int fact[MAX]; int a[MAX]; int dp[MAX][MAX]; int main() { int n; cin >> n; fact[0]=1; FORU(i,1,MAX-1) fact[i] = (fact[i-1] * i) % MOD; vi down; FOR(i,n) { cin >> a[i]; if (i > 0 && a[i] < a[i-1]) down.push_back(i); } FORU(j,0,n-1) dp[1][j] = 1; FORU(i,2,n) { dp[i][n-i]=1; FORD(j,0,n-i-1) { if (j > 0 && a[j] < a[j-1]) break; FORU(k,1,i) { if (j+i >= n) break; dp[i][j] += (((dp[k][j+i] * (ll)fact[i]) % MOD) * inv(fact[i-k])) % MOD; } } } //FORU(i,1,n) { //FORU(j,0,n-1) cout << dp[i][j] << " "; //cout << endl; //} ll res=0; FORU(i,1,n) res += dp[i][0]; res %= MOD; cout << res << endl; return 0; }