// eddy1021 #pragma GCC optimize("O3") #include using namespace std; typedef double D; typedef long double LD; typedef long long LL; typedef pair PII; typedef pair PLL; #define mod9 1000000009LL #define mod7 1000000007LL #define INF 1023456789LL #define INF16 10000000000000000LL #define eps 1e-9 #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(), (x).end() #ifndef ONLINE_JUDGE #define debug(...) printf(__VA_ARGS__) #else #define debug(...) #endif inline LL getint(){ LL _x=0,_tmp=1; char _tc=getchar(); while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar(); if( _tc == '-' ) _tc=getchar() , _tmp = -1; while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar(); return _x*_tmp; } inline LL add( LL _x , LL _y , LL _mod = mod7 ){ _x += _y; return _x >= _mod ? _x - _mod : _x; } inline LL sub( LL _x , LL _y , LL _mod = mod7 ){ _x -= _y; return _x < 0 ? _x + _mod : _x; } inline LL mul( LL _x , LL _y , LL _mod = mod7 ){ _x *= _y; return _x >= _mod ? _x % _mod : _x; } LL mypow( LL _a , LL _x , LL _mod ){ if( _x == 0 ) return 1LL; LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod ); if( _x & 1 ) _ret = mul( _ret , _a , _mod ); return _ret; } LL mymul( LL _a , LL _x , LL _mod ){ if( _x == 0 ) return 0LL; LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod ); if( _x & 1 ) _ret = add( _ret , _a , _mod ); return _ret; } inline bool equal( D _x , D _y ){ return _x > _y - eps && _x < _y + eps; } #define Bye exit(0) int __ = 1 , _cs; /*********default*********/ #define N 1234 int C[ N ][ N ] , fac[ N ]; void build(){ for( int i = 0 ; i < N ; i ++ ) C[ i ][ 0 ] = C[ i ][ i ] = 1; for( int i = 2 ; i < N ; i ++ ) for( int j = 1 ; j < i ; j ++ ) C[ i ][ j ] = add( C[ i - 1 ][ j ] , C[ i - 1 ][ j - 1 ] ); fac[ 0 ] = 1; for( int i = 1 ; i < N ; i ++ ) fac[ i ] = mul( fac[ i - 1 ] , i ); } int n , a[ N ] , ans; void init(){ n = getint(); for( int i = 1 ; i <= n ; i ++ ) a[ i ] = getint(); } int dp[ N ][ N ]; bool gt[ N ][ N ]; int DP( int x , int g ){ if( x > n or g == 1 ) return 1; if( gt[ x ][ g ] ) return dp[ x ][ g ]; int ret = 0; for( int i = x ; i <= n and i < x + g ; i ++ ){ if( i > x and a[ i ] < a[ i - 1 ] ) break; ret = add( ret , mul( mul( C[ g ][ i - x + 1 ] , fac[ i - x + 1 ] ) , DP( i + 1 , i - x + 1 ) ) ); } gt[ x ][ g ] = true; return dp[ x ][ g ] = ret; } void solve(){ for( int i = 1 ; i <= n ; i ++ ){ if( a[ i ] < a[ i - 1 ] ) break; ans = add( ans , DP( i + 1 , i ) ); } printf( "%d\n" , ans ); } int main(){ build(); //__ = getint(); while( __ -- ){ init(); solve(); } }