#include using namespace std; const int N = 1220, MOD = 1000000007; int fac[N], invfac[N], f[N][N]; void add(int &x, int y) { x += y; if (x >= MOD) { x -= MOD; } } int pw(int x, int y) { int ans = 1; for (; y; y >>= 1, x = 1ll * x * x % MOD) { if (y & 1) { ans = ans * 1ll * x % MOD; } } return ans; } int inv(int x) { return pw(x, MOD - 2); } int c(int x, int y) { if (x < y) { return 0; } return 1ll * fac[x] * invfac[y] % MOD * invfac[x - y] % MOD; } int main() { int n; cin >> n; vector m(n); for (int m_i = 0; m_i < n; m_i++) { cin >> m[m_i]; } fac[0] = 1; invfac[0] = inv(1); for (int i = 1; i < N; i++) { fac[i] = fac[i - 1] * 1ll * i % MOD; invfac[i] = inv(fac[i]); } // your code goes here int last = -1; for (int i = 0; i < n; i++) { if (m[i] < last) { break; } f[0][i] = 1; last = m[i]; } for (int i = 0; i < n; ++i) { for (int j = i; j < n; ++j) { if (f[i][j]) { // cout << i << " " << j << " " << f[i][j] << endl; int l1 = j - i + 1; last = -1; for (int k = j + 1; k < n; ++k) { int l2 = k - j; if (l2 > l1 || m[k] < last) { break; } add(f[j + 1][k], f[i][j] * 1ll * c(l1, l2) % MOD * fac[l2] % MOD); last = m[k]; } } } } int ans = 0; for (int i = 0; i < n; ++i) { add(ans, f[i][n - 1]); } cout << ans << endl; return 0; }