#include #define FOR(x,n) for(int x = 0; x < n; x++) #define ALL(a) (a).begin(), (a).end() #define SZ(a) ((int)(a).size()) using namespace std; typedef long long ll; const ll MOD = 1e9 + 7LL; const int MXN = 1201; int N, A[MXN], B[MXN]; ll m[MXN][MXN] = {}, facts[MXN], invs[MXN]; ll solve(int i, int sz){ if(i == N) return 1LL; if(m[i][sz] != -1) return m[i][sz]; m[i][sz] = 0; for(int x = i; x <= N-1 && x <= B[i] && x-i+1 <= sz; x++){ ll tmp = (facts[sz] * invs[sz - (x-i+1)])%MOD; m[i][sz] = (m[i][sz] + (tmp * solve(x+1,x-i+1))%MOD)%MOD; } return m[i][sz]; } ll bE(ll b, ll e){ ll r = 1; while(e) if(e&1) r=(r*b)%MOD, e--; else b=(b*b)%MOD, e>>=1; return r; } int main() { memset(m,-1,sizeof m); cin >> N; facts[0] = 1; FOR(x,MXN-1) facts[x+1] = ((ll)(x+1) * facts[x])%MOD; FOR(x,MXN) invs[x] = bE(facts[x], MOD-2LL); FOR(x,N) cin >> A[x]; for(int x = N-1; x >= 0; x--) if(x == N-1 || A[x] > A[x+1]) B[x] = x; else B[x] = B[x+1]; ll ans = 0; for(int x = 0; x <= B[0]; x++) ans = (ans + solve(x+1,x+1))%MOD; cout << ans << "\n"; }