#include #define all(x) (x).begin(), (x).end() using namespace std; inline int nxt() { int x; scanf("%d", &x); return x; } const int mod = 1000000007; const int N = 1234; long long C[N][N]; long long dp[N][N]; long long fact[N]; long long inv[N]; long long invfact[N]; int main() { int n = nxt(); vector a(n); for (int i = 0; i < n; ++i) { a[i] = nxt(); } invfact[0] = 1; for (int i = 1; i < N; ++i) { inv[i] = 1; while (inv[i] % i) { inv[i] += mod; } inv[i] /= i; invfact[i] = invfact[i - 1] * inv[i] % mod; } fact[0] = 1; for (int i =0 ; i < N; ++i) { C[i][0] = C[i][i] = 1; for (int j = 1; j < i; ++j) { C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; } if (i) { fact[i] = fact[i - 1] * i % mod; } } dp[n - 1][0] = 1; for (int i = n - 2; i >= 0 && a[i] < a[i + 1]; --i) { dp[i][0] = 1; } for (int i = n - 2; i >= 0; --i) { for (int cnt = 2; i + cnt <= n && (i + cnt == n || a[i + cnt - 1] < a[i + cnt]); ++cnt) { if (i + cnt == n) { dp[i][cnt - 1] = fact[cnt]; break; } for (int j = 1; j <= cnt; ++j) { dp[i][cnt - 1] += C[cnt][j] * dp[i + cnt][j - 1]; } dp[i][cnt - 1] %= mod; dp[i][cnt - 1] = dp[i][cnt - 1] * fact[cnt] % mod; } } for (int i = 0; i < n; ++i) { dp[0][i] = dp[0][i] * invfact[i + 1] % mod; } cout << accumulate(dp[0], dp[0] + n, 0ll) % mod << "\n"; return 0; }