#include using namespace std; int n,a[1210],c[1210][1210]; long long p[1210],r[1210],f[1210][1210],mod=1e9+7,A[1210][1210]; inline long long exp(long long a,long long b) { long long ret=1; while (b) { if (b&1) ret*=a,ret%=mod; a*=a; a%=mod; b>>=1; } return ret; } long long F(int u,int v) { if (f[u][v]!=-1) return f[u][v]; if (u==v and c[1][u]) return 1; if (u==v) return 0; if (!c[u-v+1][u]) return 0; f[u][v]=0; for (int i=v;i<=u-v;i++) f[u][v]+=(F(u-v,i)*A[i][i-v])%mod; f[u][v]%=mod; return f[u][v]; } int main() { scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); for (int i=1;i<=n;i++) { c[i][i]=1; for (int j=i+1;j<=n;j++) if (a[j]>a[j-1]) c[i][j]=1; else break; } p[0]=r[0]=1; for (int i=1;i<=n;i++) p[i]=p[i-1]*i,p[i]%=mod,r[i]=exp(p[i],mod-2); for (int i=0;i<=n;i++) for (int j=0;j<=n;j++) A[i][j]=(p[i]*r[j])%mod,f[i][j]=-1; int ret=0; for (int i=1;i<=n;i++) ret+=F(n,i),ret%=mod; cout << ret; }