#include using namespace std; #define ll long long #define pb push_back //#define mp make_pair #define fr first #define sc second #define ARRS int(2e5+11) #define MAX ((long long)(1e9+1)) #define HS1 ((long long)(1000001329)) #define HS2 ((long long)(1000001531)) #define MOD ((long long)1000000007ll) #define PI 3.14159265358979323846264338327950288419716 ll a[ARRS]; ll b[ARRS]; ll s[ARRS]; ll f[ARRS]; ll m[ARRS]; ll dp[3000][3000]; ll fc[3000][3000]; vector vc[ARRS]; ll vs[ARRS]; ll poww(ll a,ll b){ ll p=1; while(b){ if(b&1)p=(p*a)%MOD; a=(a*a)%MOD; b>>=1; } return p; } int main(){ #ifdef KHOKHO freopen("in.in","r",stdin); freopen("out.out","w+",stdout); #endif //KHOKHO ll sa,e,q,p,g,i,n,kk,x,k,pas,j; cin>>n; f[0]=1; for(int i=1; i<10000; i++){ f[i]=(f[i-1]*i)%MOD; } for(int i=0; i<1400; i++){ for(int j=0; j<1400; j++){ fc[i][j] = (f[i]*poww(f[j],MOD-2))%(MOD); } } for(int i=1; i<=n; i++){ cin>>a[i]; // if(a[i]>a[i-1])c++; // else c=0,v.pb(c); } a[0]=-10; //for(int i=0; i<=n; i++){ // dp[0][i]=1; // } dp[0][n]=1; for(int i=1; i<=n; i++){ j=i; while(1){ //cout<=i-j+1; k--){ dp[i][i-j+1]+=fc[k][k-(i-j+1)]*dp[j-1][k]; dp[i][i-j+1]%=MOD; } if(a[j]