#include using namespace std; #define F first #define S second #define FOR(i,a,b) for (int i = (a); i <= (b); ++i) #define NFOR(i,a,b) for(int i = (a); i >= (b); --i) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define cerr cout typedef long long ll; typedef pair ii; typedef vector vi; const int inf = 1e9 + 7; const ll inf2 = inf * 1LL * inf; #define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__) template void dbs(string str, T t) {cerr << str << " : " << t << "\n";} template void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);} template ostream& operator <<(ostream& os, const pair& p) {return os << "(" << p.first << ", " << p.second << ")";} template ostream& operator <<(ostream& os, const vector& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";} template ostream& operator <<(ostream& os, const set& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";} template ostream& operator <<(ostream& os, const map& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";} template void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";} const int N = 1250; int n; int m[N], nxt[N], fac[N], ifac[N], inv[N]; int dp[N][N]; int f(int i, int k) { if (i == n + 1) return 1; int & ans = dp[i][k]; if (~ans) return ans; ans = 0; FOR (j, 1, min(k, nxt[i])) { int term; if (i > 1) term = (fac[k] * 1LL * f(i + j, j)) % inf, term = (term * 1LL * ifac[k - j]) % inf; else term = f(i + j, j) % inf; ans += term; if (ans >= inf) ans -= inf; } return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); fac[0] = 1; ifac[0] = 1; inv[1] = 1; FOR (i, 1, 1200) { if (i > 1) inv[i] = (inf - ((inf / i) * 1LL * inv[inf % i]) % inf) % inf; fac[i] = (fac[i - 1] * 1LL * i) % inf; ifac[i] = (ifac[i - 1] * 1LL * inv[i]) % inf; } cin >> n; FOR (i, 1, n) cin >> m[i]; NFOR (i, n, 1) { nxt[i] = 1; if (i < n and m[i + 1] > m[i]) nxt[i] += nxt[i + 1]; } memset(dp, -1, sizeof dp); cout << f(1, n) << "\n"; return 0; }