//#pragma GCC optimize("Ofast") #define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include using namespace std; typedef long long int64; typedef unsigned long long uint64; typedef pair pii; typedef pair pll; typedef pair pli; const int INF = (int)(1e9+1e5); const int64 LINF = (int64)(4e18); const double EPS = 1e-11; const int MOD = (int)1e9 + 7; #define sq(x) ((x)*(x)) #define FAIL() ((*(int*)0)++) const int MAXN = 1205; inline int add(int a, int b) { a += b; if (a >= MOD) { a -= MOD; } return a; } inline int sub(int a, int b) { a -= b; if (a < 0) { a += MOD; } return a; } inline int mul(int a, int b) { return int64(a) * b % MOD; } inline int binpow(int a, int b) { int res = 1; while (b) { if (b & 1) { res = mul(res, a); } a = mul(a, a); b >>= 1; } return res; } int n; int A[MAXN][MAXN]; int a[MAXN]; int dp[MAXN][MAXN]; int f[MAXN], bf[MAXN]; void init() { scanf ("%d", &n); for (int i = 1; i <= n; i++) { scanf ("%d", &a[i]); } } void precalc() { f[0] = bf[0] = 1; for (int i = 1; i <= n; i++) { f[i] = mul(f[i - 1], i); bf[i] = binpow(f[i], MOD - 2); } for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { A[i][j] = mul(f[i], bf[i - j]); } } } void solve() { init(); precalc(); for (int i = 1; i <= n; i++) { if (a[i] < a[i - 1]) { break; } dp[i][i] = 1; } for (int i = 1; i < n; i++) { for (int j = 1; j <= i; j++) { dp[i + 1][1] = add(dp[i + 1][1], mul(dp[i][j], j)); for (int h = 2; h <= j; h++) { if (a[i + h] < a[i + h - 1]) { break; } dp[i + h][h] = add(dp[i + h][h], mul(dp[i][j], A[j][h])); } } } int ans = 0; for (int i = 1; i <= n; i++) { ans = add(ans, dp[n][i]); } printf("%d\n", ans); } int main() { //srand(time(0)); testgen(10, 5, 30); ios_base::sync_with_stdio(false); cin.tie(0); #ifdef _MY_DEBUG freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int t = 1; //scanf ("%d", &t); for (int i = 0; i < t; i++) { solve(); } return 0; }