// @betaveros :: vim:set fdm=marker syntax=cppc: // #define NDEBUG // #includes, using namespace std {{{ #include #include #include #include #include #include // C++11? #include #include #include #include #include #include #include #include #include using namespace std; // }}} // #defines, typedefs, constants {{{ #define fori(i,s,e) for(int i = s; i < ((int)e); i++) #define fori0(i,e) for(int i = 0; i < ((int)e); i++) #define fori1(i,e) for(int i = 1; i <= ((int)e); i++) #define forui(i,s,e) for(unsigned int i = s; i < ((unsigned int)e); i++) #define foruin(i,c) for(unsigned int i = 0; i < ((unsigned int)(c).size()); i++) #define _conc(x,y) x ## y #define _conc2(x,y) _conc(x,y) #define repeat(n) fori(_conc2(_,__LINE__),0,n) #define allof(s) (s).begin(), (s).end() #define scan_d(x) scanf("%d",&(x)) #define scan_dd(x,y) scanf("%d%d",&(x),&(y)) #define scan_ddd(x,y,z) scanf("%d%d%d",&(x),&(y),&(z)) #define scan_dddd(x,y,z,w) scanf("%d%d%d%d",&(x),&(y),&(z),&(w)) #define pushb push_back #define popb push_back #ifdef NDEBUG #define debug(code) #define debugf(...) ((void)0) #else #define debug(code) code #define debugf(...) fprintf(stderr, __VA_ARGS__) #endif typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef vector Vint; typedef vector::iterator Vit; // const int OO = 1000 << 20; // const int OO2 = 2000 << 20; // const int M7 = 1000000007; // const int M9 = 1000000009; const long long M7L = 1000000007L; // }}} // dump, min/maxify {{{ template void dumpBetween(const T & a, const T & b) { for (T it = a; it != b; it++) cout << *it << " "; cout << endl; } template void dumpAll(const T & a) { dumpBetween(allof(a)); } template void minify(T & a, const T & b) { if (a > b) a = b; } template void maxify(T & a, const T & b) { if (a < b) a = b; } // }}} long long mod(long long x, long long m) { long long r = x % m; return r < 0 ? r + m : r; } long long minv(long long x, long long m) { return x == 1 ? 1 : mod(minv(m % x, m) * (m - m/x), m); } long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } const int N = 1337; ll dp[N][N]; ll factorial[N]; void prep() { factorial[0] = 1; fori (i, 1, N) { factorial[i] = (i * factorial[i-1]) % M7L; } } int n; int a[N]; void readInput() { scan_d(n); fori (i, 0, n) scan_d(a[i]); } void tc() { prep(); readInput(); for (int i = n - 1; i >= 0; i--) { // dp[i][j] = ways to arrange i.. into exactly j (unordered, but // therefore all distinct) piles // there are n - i items dp[i][1] = 1; for (int j = 2; j <= n - i; j++) { if (a[i + j - 2] < a[i + j - 1]) { // ascending; is ok if (n - i == j) { // use zero nonempty pile tails dp[i][j] = 1; } else { ll arrangements = 1; for (int k = 1; k <= j; k++) { // use k nonempty pile tails arrangements *= j + 1 - k; arrangements %= M7L; dp[i][j] += (arrangements * dp[i + j][k]) % M7L; dp[i][j] %= M7L; } } } else break; } } ll ans = 0; fori (j, 0, n + 1) { ans = (ans + dp[0][j]) % M7L; } printf("%" PRId64 "\n", ans); } int main() { tc(); }