#include #define PII pair #define f first #define s second #define VI vector #define LL long long #define MP make_pair #define LD long double #define PB push_back #define ALL(V) V.begin(),V.end() #define abs(x) max((x),-(x)) #define PDD pair #define VPII vector< PII > #define siz(V) ((int)V.size()) #define FOR(x, b, e) for(int x=b;x<=(e);x++) #define FORD(x, b, e) for(int x=b;x>=(e);x--) #define REP(x, n) for(int x=0;x<(n);x++) #define mini(a,b) a=min(a,b) #define maxi(a,b) a=max(a,b) using namespace std; const int MXN = 1204; int mod = 1e9 + 7; LL mod2 = (LL)mod * mod; int in[MXN]; bool inc[MXN][MXN]; LL dp[MXN][MXN]; LL bion[MXN][MXN]; LL V(int n, int k) { return bion[n][k]; } LL silnia(int n) { LL r = 1; FOR(i, 2, n){r *= i; r%=mod;} return r; } int main() { int n; scanf("%d", &n); FOR(i, 1, n) { // in[i] = i; scanf("%d", &in[i]); } FOR(i, 0, n) bion[i][0] = 1; FOR(i, 1, n) FOR(j, 1, n) bion[i][j] = (bion[i-1][j-1] + bion[i-1][j]) % mod; FOR(i, 1, n) { LL val = 1; FOR(j, 1, n) { val *= j; val %= mod; bion[i][j] *= val; bion[i][j] %= mod; } } FOR(i, 1, n) { inc[i][i] = 1; FOR(j, i + 1, n) inc[i][j] = inc[i][j-1] & (in[j-1] < in[j]); } dp[0][n] = 1; FOR(i, 1, n) { FOR(dl, 1, i) { if(!inc[i-dl+1][i])break; FOR(j, dl, n) { dp[i][dl] += dp[i-dl][j] * (i == dl ? 1 : V(j, dl)); if(dp[i][dl] > mod2)dp[i][dl] -= mod2; } dp[i][dl] %= mod; } } LL res = 0; FOR(i, 1, n)res += dp[n][i]; res %= mod; cout<