#include using namespace std; #define fre freopen("in.txt","r",stdin) #define ll long long #define abs(x) ((x)>0?(x):-(x)) #define mod 1000000007 #define scand(x) scanf("%d",&x); #define scanlld(x) scanf("%I64d",&x); #define scans(x) scanf("%s",x); #define printd(x) printf("%d",x); #define printlld(x) printf("%I64d",x); #define fi first #define se second #define pb push_back #define mp make_pair #define inf (1<<30) #define forup(i,a,b) for(int i=a;i #define boost ios_base::sync_with_stdio(0) #define MAXN 1202 ll a[MAXN],sorted[MAXN][MAXN],dp[MAXN][MAXN]; ll fact[MAXN], inv[MAXN]; ll P(ll base, ll power) { ll res = 1; while (power) { if (power & 1) { res = (res * base) % mod; } base = (base * base) % mod; power >>= 1; } return res; } void preprocess() { inv[0] = fact[0] = 1; for (int i = 1; i < MAXN; ++i) { fact[i] = (fact[i - 1] * i) % mod; inv[i] = (inv[i - 1] * P(i, mod - 2)) % mod; } } ll C(ll n, ll k) { ll res = fact[n]; res = (res * inv[n - k]) % mod; res = (res * inv[k]) % mod; return res; } int main() { boost; //fre; preprocess(); int n; cin>>n; forup(i,1,n+1)cin>>a[i]; forup(i,1,n+1) { sorted[i][1]=1; for(int j=2;i+j-1<=n;j++)sorted[i][j]=sorted[i][j-1]&(a[i+j-1]>a[i+j-2]); } forup(i,1,n+1)if(sorted[i][n-i+1])dp[i][n-i+1]=1; for(int i=n-1;i>0;i--) { for(int j=1;j+i<=n;j++) { if(sorted[i][j]) { for(int k=j;k>0;k--) { if(sorted[i+j][k]) { dp[i][j]=(dp[i][j]+(((fact[k]*dp[i+j][k])%mod)*C(j,k))%mod)%mod; } } } } } //if(sorted[1][n])dp[1][n]=1; //cout<