// _ // _/_\_ // (O_o) // ~( )~ // (~~~) // / \ #include #define left nadnlassad #define right asdaslknd #define y1 kjdajasjdsas #define nxt accepted #define prev why_would_you_call_when_you_are_high #define pb push_back #define mp make_pair #define mt make_tuple #define f first #define s second #define ll long long #define ld long double #define ull unsigned ll #define hash_t pair #define pii pair #define uint unsigned int #define puu pair #define sqr(x) ((x) * 1LL * (x)) #define vec vector #define sz(v) int(v.size()) #define all(v) v.begin(), v.end() #define endl "\n" #define bits(x) __builtin_popcountll(x) #define forn(i, s, t) for(int i = (int) s; i <= (int) t; i++) #define form(i, t, s) for(int i = (int) t; i >= (int) s; i--) using namespace std; void rf() { #define fname "sparse" #ifdef SONY freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #else //freopen(fname".in", "r", stdin); //freopen(fname".out", "w", stdout); #endif //SONY } const int nx[8] = {2, -2, -2, 2, 1, 1, -1, -1}; const int ny[8] = {1, 1, -1, -1, 2, -2, -2, 2}; const int Nx[4] = {0, 0, -1, 1}; const int Ny[4] = {1, -1, 0, 0}; const ll LINF = (ll) 5e18; const int INF = 1e9 + 7; const int N = 2000 + 1; const int MAXN = 1e6 + 50; const double EPS = 1e-9, PI = 3.14159265359; inline int get_int() { char x = getchar(); int ret = 0; bool neg = 0; while (!('0' <= x && x <= '9')) { if (x == '-') neg = 1; x = getchar(); } while ('0' <= x && x <= '9') { ret = ret * 10 + x - '0'; x = getchar(); } if (neg) ret *= -1; return ret; } int n; int a[N]; int f[N], dp[N][N]; inline void add(int &x, int y) { x += y; if (x >= INF) x -= INF; if (x < 0) x += INF; } inline int mult(const int &x, const int &y) { return 1ll * x * y % INF; } int bp(int x, int y) { int res = 1; while (y) { if (y % 2) res = mult(res, x); x = mult(x, x); y /= 2; } return res; } int inv[N]; inline int calc(const int &n, const int &k) { return mult(f[n], inv[n - k]); } int sum(int x, int y) { add(x, y); return x; } int main() { srand(time(0)); //ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); rf(); cin >> n; f[0]=1; forn(i,1,n+10)f[i]=mult(f[i-1],i); forn(i,0,n+10)inv[i]=bp(f[i],INF-2); forn(i, 1, n) cin >> a[i]; form(cnt,n,1){ int l=1; forn(i,1,n){ if(a[i-1]>a[i])l=i; if(i==cnt){ if(l==1) dp[i][cnt]=1; continue; } if(i