#include using namespace std; const int MAXM = 1210; const long long mod = 1000000007; long long F[MAXM][MAXM]; long long S[MAXM]; long long Si[MAXM]; int M[MAXM]; long long mul_inv(long long a, long long b) { long long b0 = b, t, q; long long x0 = 0, x1 = 1; if (b == 1) return 1; while (a > 1) { q = a / b; t = b, b = a % b, a = t; t = x0, x0 = x1 - q * x0, x1 = t; } if (x1 < 0) x1 += b0; return x1; } bool isSorted(int m, int k) { for (int i=1;i> n; for(int i = 0; i < n; i++) cin >> M[i]; for (int m=n-1;m>=0;--m) F[m][1] = 1; for (int k=1;k<=n;++k) F[n-k][k] = isSorted(n-k,k) ? 1 : 0; S[0] = 1; for (int i=1;i<=n;++i) S[i] = S[i-1]*((long long)i)%mod; for (int i=0;i<=n;++i) Si[i] = mul_inv(S[i], mod); for (int k=2;k<=n;++k) { for (int m=n-k-1;m>=0;--m) { long long Fk = 0; if (isSorted(m,k)) { for (int kk=1;kk<=k;++kk) { //std::clog << ":: " << k << " " << m << " " << kk << std::endl; if (m+k+kk <= n) Fk = (Fk + F[m+k][kk] * S[k] % mod * Si[k-kk] % mod) % mod; } } F[m][k] = Fk; } } /* for (int k=1;k<=n;++k) { for (int m=0;m