#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ws ws_____________________ #define y1 y1_____________________ #define y0 y0_____________________ #define left left_________________ #define right right_______________ #define next next_________________ #define prev prev_________________ #define hash hash_________________ #define pb push_back #define fst first #define snd second #define mp make_pair #define sz(C) ((int) (C).size()) #define forn(i, n) for (int i = 0; i < int(n); ++i) #define ford(i, n) for (int i = int(n) - 1; i >= 0; --i) #define all(C) begin(C), end(C) typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair pii; typedef pair pll; typedef vector vll; typedef vector vi; typedef vector vvi; typedef vector vii; typedef long double ld; typedef complex cd; #define FILE_NAME "a" const int MOD = 1e9 + 7; const int MAXN = 1200 + 10; void add(int& x, int y) { ((x += y) >= MOD) && (x -= MOD); } int mul(int x, int y) { return x * 1ll * y % MOD; } int mpow(int a, int p) { int res = 1; for (; p > 0; a = mul(a, a), p >>= 1) { if (p & 1) { res = mul(res, a); } } return res; } int n; int a[MAXN]; bool read() { if (scanf("%d", &n) < 1) { return 0; } forn(i, n) { scanf("%d", &a[i]); } return 1; } int fact[MAXN]; int inv_fact[MAXN]; void precalc() { fact[0] = 1; for (int i = 1; i < MAXN; ++i) { fact[i] = mul(fact[i - 1], i); } forn(i, MAXN) { inv_fact[i] = mpow(fact[i], MOD - 2); assert(mul(fact[i], inv_fact[i]) == 1); } } int dp[MAXN][MAXN]; int solve() { memset (dp, 0, sizeof dp); int ans = 0; ford(l, n) { for (int r = l; r < n; ++r) { if (r > l && a[r] < a[r - 1]) { break; } int& res = dp[l][r]; int k = r - l + 1; if (r == n - 1) { res = 1; } else { for (int kk = 1; r + kk < n; ++kk) { int cur = dp[r + 1][r + kk]; if (!cur) { continue; } cur = mul(cur, inv_fact[k - kk]); add(res, cur); } res = mul(res, fact[k]); } if (l == 0) { add(ans, res); } } } return ans; } int main() { #ifdef LOCAL freopen(FILE_NAME ".in", "r", stdin); // freopen(FILE_NAME ".out", "w", stdout); #endif precalc(); while (read()) { printf("%d\n", solve()); } #ifdef LOCAL cerr.precision(5); cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl; #endif return 0; }