//Solution by Daniyar Maminov #include #include #include #include #include #include #include #include #include #include #define mp make_pair #define F first #define pb push_back #define S second #define ub upper_bound #define lb lower_bound #define inf 1e+9 #define ll long long #define ull unsigned long long using namespace std; const int maxn = 2010; const int mod = 1e+9 + 7; int dp[maxn][maxn]; int a[maxn]; int f[maxn], inv[maxn]; inline int bp(int a, int b) { int res = 1ll; while (b) { if (b & 1) { res = (res * 1ll * a) % mod; b--; } a = (a * 1ll * a) % mod; b >>= 1; } return res; } inline int F(int n, int k, int id) { if (!id) return 1; return (f[n] * 1ll * inv[n - k]) % mod; } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; f[0] = inv[0] = 1; for (int i = 1; i <= n; i++) { cin >> a[i]; f[i] = (f[i - 1] * 1ll * i) % mod; inv[i] = bp(f[i], mod - 2); } dp[0][n] = 1; for (int i = 0; i <= n; i++) { for (int len = n; len >= 1; len--) { if (!dp[i][len]) continue; // cout << i << " " << len << " < ---- > " << dp[i][len] << endl; for (int k = 1; k <= len && i + k <= n; k++) { if (k > 1 && a[i + k] < a[i + k - 1]) break; dp[i + k][k] += (dp[i][len] * 1ll * F(len, k, i)) % mod; if (dp[i + k][k] >= mod) dp[i + k][k] -= mod; } } } int ans = 0; for (int i = 1; i <= n; i++) { ans += dp[n][i]; if (ans >= mod) ans -= mod; } cout << ans; return 0; }