#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) x.begin() , x.end() #define fi first #define se second #define pb push_back #define umax( x , y ) x = max( x , (y) ) #define umin( x , y ) x = min( x , (y) ) #define For( i , a ) for(int i=1;i<=a;i++) #define ort (b+s)/2 #define y2 asrwjaelkf #define y1 asseopirwjaelkf #define set multiset using namespace std; inline int read() { int res = 0 ;int neg ; while(true){char ch = getchar();if(ch>='0' && ch<='9' || ch=='-'){if(ch=='-') neg = -1;else neg = 1 , res = ch-'0';break;} } while(true){char ch = getchar();if(ch>='0' && ch<='9') res*=10 , res+=ch-'0';else break;} return res*neg; } typedef long long Lint; typedef long double db; typedef pair ii; typedef pair dd; typedef pair di; typedef pair iii; typedef pair i4; const int maxn = 1220; const int maxm = 1000020; const int MOd = 1e9 + 7; int a, cnt = 0; void dfs( int top, int last, vector v ) { if( top > a ) return; if( top == a ) { cnt++; //for(int i=0;i= MOd ? a + b - MOd : a + b; } int us( int x, int y ) { int z = 1; while( y ) { if( y&1 ) z = mul( z, x ); x = mul( x, x ); y >>= 1; } return z; } int fakt[maxn], inv[maxn]; int per[maxn][maxn]; int ar[maxn]; int dn[maxn][maxn]; void solve() { memset( dn, 0, sizeof( dn ) ); scanf("%d",&a); for(int i=1;i<=a;i++) scanf("%d",&ar[i]); for(int i=1;i<=a;i++) if( ar[i-1] < ar[i] ) dn[i][i] = 1; else break; fakt[0] = inv[0] = 1; for(int i=1;i<=a;i++) { fakt[i] = mul( fakt[i-1], i ); inv[i] = us( fakt[i], MOd-2 ); } for(int i=1;i<=a;i++) for(int j=0;j<=i;j++) { per[i][j] = mul( fakt[i], inv[j] ); } for(int i=1;i<=a;i++) for(int j=1;j<=i;j++) { if( !dn[i][j] ) continue; for(int k=1;k<=j;k++) { if( k > 1 && ar[i+k] < ar[i+k-1] ) break; dn[i+k][k] = add( dn[i+k][k], mul( dn[i][j], per[j][j-k] ) ); } } int ans = 0; for(int i=1;i<=a;i++) ans = add( ans, dn[a][i] ); printf("%d\n",ans); } int main() { //freopen("asd.in.c","r",stdin); //freopen("out.txt","w",stdout); int n = 1; //scanf("%d",&n); while( n-- ) solve(); return 0; }