#include using namespace std; typedef long long ll; typedef long double ld; typedef vector vi; typedef pair pii; typedef pair pll; #define zhfs main #define mp(a, b) make_pair(a, b) #define fi first #define se second #define re return #define forn(i, n) for (int i = 1; i <= n; i++) const int MAXN = 1207; const ll MOD = 1000 * 1000 * 1000 + 7; int cnk[MAXN][MAXN]; int dp[MAXN][MAXN]; int a[MAXN]; bool good[MAXN][MAXN]; void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } int mul(int x, int y) { re (1LL * x * y) % MOD; } int fc[MAXN]; int zhfs() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n; scanf("%d", &n); fc[0] = 1; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); good[i][i] = true; fc[i] = mul(fc[i - 1], i); } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (good[i][j - 1] && a[j] > a[j - 1]) { good[i][j] = true; } } } cnk[0][0] = 1; for (int i = 1; i <= n; i++) { cnk[i][0] = 1; for (int j = 1; j <= i; j++) { cnk[i][j] = cnk[i - 1][j]; add(cnk[i][j], cnk[i - 1][j - 1]); } } dp[n + 1][0] = 1; for (int i = n; i >= 1; i--) { for (int j = 1; i + j - 1 <= n; j++) { int rp = i + j - 1; if (good[i][rp]) { for (int k = 0; k <= j; k++) { add(dp[i][j], mul(dp[rp + 1][k], cnk[j][k])); } } if (i != 1) { dp[i][j] = mul(dp[i][j], fc[j]); } // cerr << i << " " << j << " " << dp[i][j] << endl; } } int res = 0; for (int i = 0; i <= n; i++) { add(res, dp[1][i]); } printf("%d\n", res); }