#include #define LL long long using namespace std; const LL MOD=1e9+7; const int N=1205; int n,m[N],a[N],b[N]; LL ans,fact[N],factt[N]; LL dp[N][N]; // index, bolo zoma LL power (LL a, LL b, LL mod){ LL x=1,y=a,ans=1; while (x<=b){ if(b&x)ans=ans*y%mod; x*=2; y=y*y%mod; } return ans; } LL C (LL A, LL B){ return fact[A]*factt[A-B]%MOD; } int main() { cin>>n; fact[0]=1; factt[0]=1; for (LL i=1;i<=n;i++){ fact[i]=fact[i-1]*i%MOD; factt[i]=power(fact[i],MOD-2,MOD); } for (int i=1;i<=n;i++)cin>>m[i]; for (int i=1;i<=n;i++){ a[i]=i; b[i]=i; while (a[i]>1&&m[a[i]-1]m[b[i]])b[i]++; } for (int i=1;i<=n;i++) for (int j=1;j<=i-a[i]+1;j++){ if (j==i){dp[i][j]=1;continue;} for (int l=j;l<=i-j;l++) dp[i][j]=(dp[i][j]+C(l,j)*dp[i-j][l]%MOD)%MOD; } for (int i=1;i<=n;i++)ans=(ans+dp[n][i])%MOD; cout<