#include using namespace std; #define forup(i,a,b) for(int i=(a);i<=(b);i++) #define fre freopen("input.txt","r",stdin)//,freopen("output.txt","w",stdout) #define ll long long #define pll pair #define pii pair #define pb push_back #define F first #define S second #define M 1000000007 #define MAXN 1205 #define boost ios::sync_with_stdio(false);cin.tie(0) #define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout) #define SET(a,b) memset(a,b,sizeof(a)) int arry[MAXN][MAXN],arr1[MAXN],cnt; ll dp[MAXN][MAXN]; int tree[MAXN]; int update(int idx, int val){ while(idx<=MAXN){ tree[idx]+=val; idx+=(-idx & idx); } return 0; } int read(int idx){ int sum=0; while(idx>0){ sum+=tree[idx]; idx-=(-idx & idx); } return sum; } int main(){ // fre; boost; cin>>cnt; forup(i,1,cnt)cin>>arr1[i]; //scanf("%d",&arr1[i]); for(ll i=cnt;i>=1;i--) { arry[i][i]=1; for(ll j=i+1;j<=cnt;j++) { arry[i][j]=arry[i+1][j]; if(arr1[i]>arr1[i+1]) arry[i][j]=0; } } for(int i=cnt;i>0;i--){ dp[1][i]=1; } for(int j=2;j<=cnt;j++){ for(int i=cnt;i>0;--i){ int x=i+j-1; if(x>cnt)continue; if(!arry[i][x])continue; if(x==cnt){ dp[j][i]=1; continue; } ll val=1; for(int k=1;k<=j;k++){ val=(val*(j-k+1))%M; dp[j][i]+=(dp[k][x+1]*val)%M; dp[j][i]%=M; } } } ll answer=0; for(int i=1;i<=cnt;i++)answer=(answer+dp[i][1])%M; cout<