#include #include #include #include #include using namespace std; long long int lim = 1e9+7; long long int dn[1205][1205], arr[1205], perm[1201][1201], n; long long int solve(int left, int numarr){ /*if(left == n || numarr == 1){ return 1; }*/ if(dn[left][numarr]){ return dn[left][numarr]; } long long int res = 0, rec,mult; int take=1, lt=1+left; do { res = (res+(solve(lt, take)*perm[numarr][take])%lim)%lim; ++take; ++lt; }while( numarr>=take && lt <= n && arr[lt-1]>=arr[lt-2] ); return (dn[left][numarr]=res); } int main() { cin>>n; for(int i=0; i> arr[i]; } for(int i=0; i<=n; ++i) dn[i][1]=1; for(int i=0; i<=n; ++i) dn[n][i]=1; long long int res = 0, rec,mult; for( int i=1 ; i<=n ; i++ ){ perm[i][1] = i; for( int j=2 ; j<=i ; j++ ) perm[i][j] = (perm[i][j-1]*(i-j+1))%lim; } int left = 0,take=1, numarr=n,lt=1; do { res = (res+solve(take, take))%lim; ++take; }while( take <= n && arr[take-1]>=arr[take-2] ); cout << res; return 0; }