#include using namespace std; const long long MOD = 1e9+7; long long F[ 1300 ], INV[ 1300 ]; int a[ 1300 ]; long long eleva( long long x ,long long n , long long MOD ){ long long ans = 1; while ( n ){ if ( n & 1 ) ans = (ans * x)%MOD; n >>= 1LL; x = ( x * x )%MOD; } return ans; } long long memo[ 1203 ][ 1203 ]; int n; long long dp( int pos , int x ){ if ( pos == n ) return 1; if ( memo[ pos ][ x ] != -1 ) return memo[ pos ][ x ]; long long &ans = memo[ pos ][ x ] = 0; for ( int i = pos ; i < pos + x ; i++ ){ if ( i == pos ){ ans = ( ans + (x*dp( i + 1 , i - pos + 1 ))%MOD )%MOD; }else{ if ( a[ i - 1 ] > a[ i ] ) break; long long val = (F[ x ]*INV[ x - ( i - pos + 1 ) ])%MOD; ans = ( ans + ( val*dp( i + 1 , i - pos + 1 ))%MOD )%MOD; } } return ans; } int main(){ cin>>n; for ( int i = 1; i <= n ; i++ ) cin>>a[i-1]; if ( n == 1 ){ cout<<1< a[ j ] ) ok = 1; } if ( !ok ) ans = ( ans + dp( i , i ) )%MOD; } cout<