#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define N 1500 #define M 1850 mt19937 gen; #define forn(i, n) for (int i = 0; i < n; i++) #define piii pair> #define pii pair #define forlrv(i, l, r) for (int i = r; i >= l; i--) #define y(p) p.second #define mp make_pair #define mpp(a, b, c) mp(a, mp(b, c)) typedef long long ll; typedef unsigned long long ull; #define forlr(i, l, r) for (int i = l; i <= r; i++) #define p p2 int n; int w[N]; ll d[N][N]; ll f[N], tr[N][N]; ll mod = 1000000007; void solve() { cin >> n; forlr(i, 1, n) cin >> w[i]; forlr(i, 1, n) { if (w[i] < w[i - 1]) break; d[i][i] = 1; } forlr(i, 0, n) tr[i][0] = 1; forlr(i, 1, n) forlr(j, 1, i) tr[i][j] = (tr[i - 1][j - 1] + tr[i - 1][j]) % mod; f[0] = 1; forlr(i, 1, n) f[i] = (f[i - 1] * i) % mod; forlr(i, 1, n) forlr(j, 1, n) if (d[i][j]) for (int u = 1; u <= j && i + u <= n; u++) { if (u > 1 && w[i + u] < w[i + u - 1]) break; d[i + u][u] = (d[i + u][u] + (((d[i][j] * f[u]) % mod) * tr[j][u]) % mod) % mod; } ll sum = 0; forlr(i, 1, n) sum = (sum + d[n][i]) % mod; cout << sum << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); }