/* ID: szhu0081 PROG: milk4 LANG: C++11 */ #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define MAXN 1205 #define MOD 1000000007 ll n; ll a[MAXN]; ll mxSize[MAXN]; ll dp[MAXN][MAXN]; ll ncr[MAXN][MAXN]; ll fac[MAXN]; void buildncr(){ ncr[0][0] = 1; ncr[1][0] = 1; ncr[1][1] = 1; for (ll i = 2; i < MAXN; i++){ for (ll j = 0; j <= i; j++){ if (j == 0 || j == i) ncr[i][j] = 1; ncr[i][j] = (ncr[i-1][j] + ncr[i-1][j-1])%MOD; } } fac[0] = 1; for (ll i = 1; i < MAXN; i++){ fac[i] = (fac[i-1] * i) % MOD; } } ll solve(ll ind, ll len){ if (ind >= n) return 1; if (dp[ind][len] != -1){ return dp[ind][len]; } ll nextInd = ind + len; ll nextLen = min(mxSize[nextInd],len); dp[ind][len] = 0; if (nextLen == 0){ dp[ind][len] = 1; } for (ll j = 1; j <= nextLen; j++){ dp[ind][len] = (dp[ind][len] + ((ncr[len][j] * fac[j] )%MOD)* solve(nextInd, j)) % MOD; } return dp[ind][len]; } int main() { buildncr(); cin >> n; memset(dp, -1, sizeof(dp)); memset(mxSize, 0, sizeof(mxSize)); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++){ for (int j = i; j < n; j++){ mxSize[i]++; if (a[j+1] < a[j]) break; } } ll res = 0; for (ll i = 1; i <= mxSize[0]; i++){ res = (res + solve(0, i)) % MOD; } cout << res << endl; }