#include using namespace std; #define FORE(it, a) for (auto it = a.begin(); it != a.end(); ++it) #define REPU(i, a, b) for (int i = (a); i < (b); ++i) #define REPD(i, a, b) for (int i = (a); i > (b); --i) #define MEM(a, x) memset(a, x, sizeof(a)) #define ALL(a) a.begin(), a.end() #define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) vector split(const string &s, char c) { vector v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return v; } #define DEBUG(args...) { vector _v = split(#args, ','); err(_v.begin(), args); } void err(vector::iterator it) {} template void err(vector::iterator it, T a, Args... args) { cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n'; err(++it, args...); } typedef long long ll; const int MOD = 1000000007; template inline T tmin(T a, U b) { return (a < b) ? a : b; } template inline T tmax(T a, U b) { return (a > b) ? a : b; } template inline void amax(T &a, U b) { if (b > a) a = b; } template inline void amin(T &a, U b) { if (b < a) a = b; } template inline T tabs(T a) { return (a > 0) ? a : -a; } template T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; } const int N = 1205; int m[N], to[N], dp[N][N], s[N][N], comb[N][N]; ll ft[N]; int main(int argc, char *argv[]) { ios_base::sync_with_stdio(false); ft[0] = 1; REPU(i, 1, N) ft[i] = i * ft[i - 1] % MOD; REPU(i, 0, N) { comb[i][i] = 1; REPU(j, i + 1, N) { comb[i][j] = (comb[i][j - 1] + (i ? comb[i - 1][j - 1] : 0)) % MOD; } } int n; cin >> n; REPU(i, 1, n + 1) cin >> m[i]; to[1] = 1; REPU(i, 2, n + 1) { if (m[i] > m[i - 1]) to[i] = to[i - 1]; else to[i] = i; } REPU(i, 1, n + 1) { int mx = to[i] - 1; REPD(j, i, mx) { int l = i - j + 1; ll res = 0; if (j > 1) { REPU(k, l, j) res += dp[j - 1][k] * 1LL * comb[l][k] % MOD; res %= MOD; res = (res * ft[l]) % MOD; } else res = 1; dp[i][l] = res; } } ll ans = 0; REPU(i, 1, n + 1) ans += dp[n][i]; ans %= MOD; cout << ans << endl; return 0; }