#pragma comment(linker, ”/STACK:36777216“) #include #define x first #define y second #define y0 hi1 #define y1 hi2 #define ll long long #define mp make_pair #define pb push_back #define sqr(a) (a)*(a) #define ld long double #define all(a) (a).begin(), (a).end() using namespace std; const int inf = 2000000000; const int N = 1205; const int md = 1e9 + 7; ll fact[N], _fact[N]; ll dp[N][N]; int n, a[N]; bool sorted[N][N]; int binpow(int a, int b){ if(b == 0){ return 1; } if(b % 2){ return 1ll * a * binpow(a, b - 1) % md; } ll f = binpow(a, b / 2); return f * f % md; } int inv(int a){ return binpow(a, md - 2); } int A(int n, int k){ return fact[n] * _fact[n - k] % md; } int f(int x, int h){ //cout << x << " " << h << "\n"; /* if(x == 0 || h == 1){ return 1; } */ if(x == 0){ return 1; } if(dp[x][h] != -1){ return dp[x][h]; } dp[x][h] = 0; for(int i = 1; i <= min(x, h); i++){ if(sorted[n - x + 1][n - x + i]){ dp[x][h] = (dp[x][h] + 1ll * A(h, i) * f(x - i, i) % md) % md; } else { break; } } return dp[x][h]; } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); fact[0] = 1; _fact[0] = inv(fact[0]); for(int i = 1; i < N; i++){ fact[i] = fact[i - 1] * i % md; _fact[i] = inv(fact[i]); } cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; //a[i] = i; } for(int i = 1; i <= n; i++){ sorted[i][i] = true; for(int j = i + 1; j <= n; j++){ sorted[i][j] = sorted[i][j - 1]; sorted[i][j] &= (a[j] >= a[j - 1]); if(!sorted[i][j]){ break; } } } ll ans = 0; memset(dp, -1, sizeof(dp)); for(int i = 1; i <= n; i++){ if(sorted[1][i]){ ll cur = f(n - i, i); ans = (ans + cur) % md; //cout << i << " " << cur << "\n"; } else { break; } } cout << ans; }