#include using namespace std; #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define ll long long #define pll pair #define pii pair #define pb push_back #define F first #define S second #define mod 1000000007 #define maxn 1205 int sorted[maxn][maxn],m[maxn],n; ll dp[maxn][maxn]; int main(){cin>>n; rep(i,1,n)scanf("%d",&m[i]); for(ll i=n;i>=1;i--) { sorted[i][i]=1; for(ll j=i+1;j<=n;j++) { sorted[i][j]=sorted[i+1][j]; if(m[i]>m[i+1]) sorted[i][j]=0; } } for(int i=n;i>0;i--){ dp[1][i]=1; //dp[i][n+1]=1; } for(int j=2;j<=n;j++){ for(int i=n;i>0;--i){ int x=i+j-1; if(x>n)continue; if(!sorted[i][x])continue; if(x==n){ dp[j][i]=1; continue; } ll val=1; for(int k=1;k<=j;k++){ val=(val*(j-k+1))%mod; dp[j][i]+=(dp[k][x+1]*val)%mod; dp[j][i]%=mod; } } } ll ans=0; for(int i=1;i<=n;i++)ans=(ans+dp[i][1])%mod; printf("%lld",ans); }