#include using namespace std; int main(){ int n; cin >> n; vector m(n); for(int m_i = 0; m_i < n; m_i++){ cin >> m[m_i]; } vector> f(n + 1, vector(n + 1, 0)); vector> A(1201, vector(1201, 0)); f[0][1] = 1; for (int i = 1; i < n && m[i] >= m[i - 1]; i++) { f[i][i + 1] = 1; } const int mod = 1e9 + 7; for (int i = 1; i <= 1200; i++) { A[i][1] = i; for (int j = 2; j <= i; j++) { A[i][j] = A[i][j - 1] * (long long)(i - j + 1) % (long long)mod; } } for (int i = 0; i < n - 1; i++) for (int j = 1; j <= i + 1; j++) if (f[i][j] > 0) { for (int k = i + 1; k < n && k <= i + j && (k == i + 1 || m[k] >= m[k - 1]); k++) { f[k][k - i] += (long long)f[i][j] * A[j][k - i] % (long long) mod; if (f[k][k - i] >= mod) { f[k][k - i] -= mod; } } } int ans = 0; for (int i = 1; i <= n; i++) { ans += f[n - 1][i]; if (ans >= mod) { ans -= mod; } } cout << ans << endl; // your code goes here return 0; }