#include #define mod 1000000007 #define C(n,k) ( ( (fact[n]*factin[n-k])%mod) * factin[k])%mod #define P(n,k) ( (fact[n]*factin[n-k])%mod)%mod using namespace std; long long D [ 1201 ] [ 1201 ] , fact [ 1250 ] , factin [ 1250 ] ; int crec [ 1201 ] , n ; long long expo ( long long b , int ex ) { if ( ex == 0 ) return 1 ; if ( ex == 1 ) return b ; long long r = expo ( b , ex >> 1 ) ; if ( ex & 1 ) return ( ( ( r * r ) % mod ) * b ) % mod ; return ( r * r ) % mod ; } long long dp (int p , int x ){ if ( p + x > crec [ p ] || p + x > n) return 0 ; if ( p + x == n ) return 1 ; if ( D [ p ] [ x ] != -1 ) return D [ p ] [ x ] ; long long ans = 0 ; for ( int i = 1 ; i <= x ; i ++ ) ans = ( ans + dp ( p + x , i ) * P ( x , i ) ) % mod ; return D [ p ] [ x ] = ans; } int main(){ ios::sync_with_stdio ( 0 ) ; cin.tie ( NULL ) ; memset ( D , -1 , sizeof D ) ; fact [ 0 ] = factin [ 0 ] = 1 ; for( long long i = 1 ; i < 1250 ; i++ ) fact [ i ] = ( fact [ i - 1 ] * i ) % mod ; for ( int i = 1 ; i < 1250 ; i ++ ) factin [ i ] = expo ( fact[i] , 1000000005 ) ; cin >> n ; int x = 0 ; vector v ( n ) ; int b = 0 ; for ( int i = 0 ; i < n ; i ++ ) { cin >> v [ i ] ; if ( i > 0 ) if ( v [ i ] < v [ i - 1 ] ) while ( b < i ) crec [ b ++ ] = i ; } while ( b < n ) crec [ b ++ ] = n ; long long re = 0 ; for(int i = 1 ; i <= crec[0] ; i ++ ) re = ( re + dp ( 0 , i ) ) % mod ; cout << re % mod << endl ; return 0; }