#include #include #include #include #include #include using namespace std; typedef long long LL; typedef vector VI; #define REP(i,n) for(int i=0, i##_len=(n); i inline void amin(T &x, const T &y) { if (y inline void amax(T &x, const T &y) { if (x void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); } putchar('\n'); } template struct ModInt { static const unsigned static_MOD = MOD; unsigned x; void undef() { x = (unsigned)-1; } bool isnan() const { return x == (unsigned)-1; } inline int getInt() const { return (int)x; } ModInt() { x = 0; } ModInt(const ModInt &y) { x = y.x; } ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; } ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; } ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; } ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; } ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; } ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; } ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; } ModInt operator-() const { return (x ? MOD-x: 0); } ModInt inv() const { unsigned a = MOD, b = x; int u = 0, v = 1; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += MOD; return ModInt(u); } ModInt pow(long long y) const { ModInt b = *this, r = 1; if (y < 0) { b = b.inv(); y = -y; } for (; y; y>>=1) { if (y&1) r *= b; b *= b; } return r; } friend ModInt operator+(ModInt x, const ModInt y) { return x += y; } friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; } friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; } friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); } friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; } friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; } friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; } static ModInt buffered_inv(const ModInt y) { static ModInt *inv_tbl = NULL; if (inv_tbl == NULL) { const int n = 2000001; inv_tbl = new ModInt[n]; inv_tbl[0] = 0; inv_tbl[1] = 1; for (int i=2; i Mint; int N; int A[100111]; Mint fact[2001], fact_inv[2001]; Mint dp[1300][1300]; int main() { fact[0] = fact_inv[0] = 1; for (int i=1; i<=2000; i++) { fact[i] = fact[i-1] * i; fact_inv[i] = fact_inv[i-1] * Mint::buffered_inv(i); } scanf("%d", &N); REP (i, N) scanf("%d", A+i); dp[N][0] = 1; for (int i=N; i--; ) { for (int j=i+1; j<=N; j++) { for (int k=0; k<=j-i; k++) { dp[i][j-i] += dp[j][k] * fact[j-i] * fact_inv[j-i-k]; } if (A[j] <= A[j-1]) break; } } Mint ans = 0; REP (i, N+1) ans += dp[0][i]; printf("%d\n", ans.getInt()); return 0; }