#include using namespace std; const int N = 1205; const int mod = 1000000007; inline int add(int a, int b) { int res = a + b; if (res < 0) res += mod; if (res >= mod) res -= mod; return res; } inline int mul(int a, int b) { return (a * 1LL * b) % mod; } int power(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = mul(res, a); a = mul(a, a); b /= 2; } return res; } int a[N], dp[N][N][2], fac[N], ifac[N]; int nPr(int n, int r) { assert(n >= r); return mul(fac[n], ifac[n - r]); } // ith pos and last row has d elements int f(int i, int d, int nf) { if (dp[i][d][nf] != -1) return dp[i][d][nf]; int& res = (dp[i][d][nf] = 0); if (i == 0) { return res = 1; } for (int j = i; i - j + 1 <= d && j > 0; --j) { int ply = nf == 0 ? 1 : nPr(d, i - j + 1); if (j < i && a[j - 1] < a[j]) break; res = add(res, mul(ply, f(j - 1, i - j + 1, nf | 1))); } return res; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", a + i); } reverse(a, a + n); memset(dp, -1, sizeof(dp)); fac[0] = ifac[0] = 1; for (int i = 1; i <= n; ++i) { fac[i] = mul(fac[i - 1], i); ifac[i] = power(fac[i], mod - 2); } printf("%d\n", f(n, n, 0)); return(0); }