#include #include #include #include #include const int max_n = 1234; const int mod = 1e9 + 7; int a[max_n]; int b[max_n]; int dp[max_n][max_n]; int comb[max_n][max_n]; int facts[max_n]; int bin_pow(int a, int b) { int r = 1; while (b > 0) { if (b & 1) { r = (long long) r * a % mod; } b >>= 1; a = (long long) a * a % mod; } return r; } int nAk(int n, int k) { int& result = comb[n][k]; if (result != 0) { return result; } return result = (long long) facts[n] * bin_pow(facts[n - k], mod - 2) % mod; } int main() { facts[0] = 1; for (int i = 1; i < max_n; ++i) { facts[i] = (long long) facts[i - 1] * i % mod; } int n; std::cin >> n; for (int i = 1; i <= n; ++i) { std::cin >> a[i]; } b[1] = 1; for (int i = 2; i <= n; ++i) { if (a[i] < a[i - 1]) { b[i] = b[i - 1] + 1; } else { b[i] = b[i - 1]; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= i; ++j) { if (b[i - j + 1] != b[i]) { break; } int k = i - j; if (k == 0) { dp[i][j] = 1; } else { for (int p = j; p <= k; ++p) { auto v = dp[k][p]; if (v > 0) { int x = (long long) v * nAk(p, j) % mod; dp[i][j] = (dp[i][j] + x) % mod; } } } } } int answer = 0; for (int i = 1; i <= n; ++i) { answer = (answer + dp[n][i]) % mod; } std::cout << answer << std::endl; }