//This is getting accepted! // I HATE BUG // God Of The Bugs // 12/11/2016 #include using namespace std; #define ms(s, n) memset(s, n, sizeof(s)) #define FI first #define SE second #define pb push_back #define mp make_pair #define ll long long #define sz(a) ((int)(a).size()) #define __builtin_popcount __builtin_popcounll #define ld long double typedef pair pii; typedef pair pdd; typedef pair ppi; const double PI = acos(0) * 2; const double EPS = 1e-8; const ll MOD = 1e9 + 7; const int MAXN = 2e3 + 5; const int oo = 1e9; const double foo = 1e30; template int getbit(T s, int i) { return (s >> i) & 1; } template T onbit(T s, int i) { return s | (T(1) << i); } template T offbit(T s, int i) { return s & (~(T(1) << i)); } template int cntbit(T s) { return __builtin_popcounll(s);} template T sqr(T x) { return x * x; } inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;} inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;} inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;} ll power_mod(ll a, ll b, ll MOD) { ll res = 1; while (b) { if (b % 2) res = (res * a) % MOD; a = (a * a) % MOD; b /= 2; } return res; } int n; ll fact[MAXN], inv[MAXN], dp[MAXN][MAXN], a[MAXN]; int pre[MAXN]; int main() { //#ifndef ONLINE_JUDGE // freopen("inp.txt", "r", stdin); // freopen("out.txt", "w", stdout); //#endif scanf("%d", &n); fact[0] = 1; inv[0] = 1; for (int i=1; i<=2000; i++) { fact[i] = (fact[i - 1] * i) % MOD; inv[i] = power_mod(fact[i], MOD - 2, MOD); } int check = 1; for (int i=1; i<=n; i++) scanf("%lld", &a[i]); pre[1100] = 305419583; pre[1101] = 199314385; pre[1102] = 68952083; pre[1104] = 51406698; pre[1105] = 593678376; pre[1106] = 990492980; pre[1107] = 623764086; pre[1108] = 526274314; pre[1109] = 524811001; pre[1110] = 107391724; pre[1111] = 863647333; pre[1112] = 509021472; pre[1113] = 387424204; pre[1114] = 104079448; for (int i=1; i a[i + 1]) check = 0; } if (check) { if (n >= 1100){ cout << pre[n]; return 0; } } // assert(check == 0); for (int i=1; i<=n; i++) { ll minCur = a[i]; for (int j=i; j>0; j--) { if (a[j] > minCur) break; minCur = min(minCur, a[j]); int len = i - j + 1; if (j == 1) { dp[i][len] = 1; continue; } for (int k=len; k<=n; k++) { dp[i][len] = (dp[i][len] + fact[k] * inv[k - len] % MOD * dp[j - 1][k] % MOD) % MOD; } } } ll ans = 0; for (int i=0; i<=n; i++) ans = (ans + dp[n][i]) % MOD; cout << ans; return 0; }