#include #include #include #include #define f first #define s second #define pb push_back #define mp make_pair #define sz(x) (int)x.size() #define sqr(x) ((x) * 1ll * (x)) #define all(x) x.begin(), x.end() #define rep(i, l, r) for (int i = l; i <= r; i++) #define per(i, l, r) for (int i = l; i >= r; i--) #define dbg(x) cerr << (#x) << " --> " << (x) << nl; #define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0); #define nl '\n' #define ioi exit(0); #define _12day "" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int N = 2e3 + 7, inf = 1e9 + 7, mod = 1e9 + 7; const ll linf = (ll)1e18 + 7; const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; int n; int a[N], dp[N][N], c[N][N]; ll f[N]; inline void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } inline int sum(int x, int y) { add(x, y); return x; } inline int mult(int x, int y) { return (x * 1ll * y) % mod; } inline int bp(int x, int y) { int res = 1; while (y) { if (y & 1) res = mult(res, x); x = mult(x, x), y >>= 1; } return res; } inline int C(int n, int k) { if (!n) return !k; if (~c[n][k]) return c[n][k]; int res = sum(C(n - 1, k), C(n - 1, k - 1)); return c[n][k] = res; } inline int get(int n, int k) { return mult(C(n, k), f[k]); } inline int calc(int v = 1, int can = n) { if (v > n) return 1; if (~dp[v][can]) return dp[v][can]; int res = 0, ptr = v; while (a[ptr] < a[ptr + 1] && ptr + 1 <= min(n, v + can - 1)) ptr++; rep(i, v, ptr) { if (v != 1) add(res, mult(calc(i + 1, i - v + 1), get(can, i - v + 1))); else add(res, calc(i + 1, i - v + 1)); } return dp[v][can] = res; } int main() { #ifdef _12 freopen (_12day".in", "r", stdin); freopen (_12day".out", "w", stdout); #endif scanf ("%d", &n); f[0] = 1; rep(i, 1, n) { scanf ("%d", &a[i]); f[i] = mult(f[i - 1], i); } memset(c, -1, sizeof(c)); memset(dp, -1, sizeof(dp)); rep(i, 1, n) rep(j, 1, n) C(i, j); cout << calc(); ioi }