#include #include using namespace std; const int mod = 1e9 + 7; const int N = 1234; long long m[N], dp[N][N], cnt[N][N]; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> m[i]; for (int i = 1; i <= n; i++) { cnt[i][0] = 1; cnt[0][i] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { cnt[i][j] = (cnt[i][j - 1] * (i - j + 1)) % mod; } } dp[n + 1][0] = 1; for (int i = n + 1; i >= 1; i--) { for (int j = i - 1; j >= 1; j--) { if (j < i - 1 && m[j] > m[j + 1]) break; for (int k = 0; k <= i - j; k++) dp[j][i - j] = (dp[j][i - j] + dp[i][k] * cnt[i - j][k]) % mod; } } long long result = 0; for (int i = 0; i <= n; i++) { result = (result + dp[1][i]) % mod; } cout << result << "\n"; return 0; }