// spnauT // #include using namespace std; #define FOR(i,a,b) for(int _b=(b),i=(a);i<_b;++i) #define ROF(i,b,a) for(int _a=(a),i=(b);i>_a;--i) #define REP(n) for(int _n=(n);_n--;) #define _1 first #define _2 second #define PB(x) push_back(x) #define SZ(x) int((x).size()) #define ALL(x) (x).begin(),(x).end() #define MSET(m,v) memset(m,v,sizeof(m)) #define MAX_PQ(T) priority_queue #define MIN_PQ(T) priority_queue,greater> #define IO(){ios_base::sync_with_stdio(0);cin.tie(0);} #define nl '\n' #define cint1(a) int a;cin>>a #define cint2(a,b) int a,b;cin>>a>>b #define cint3(a,b,c) int a,b,c;cin>>a>>b>>c typedef long long LL;typedef pair PII; typedef vectorVI;typedef vectorVL;typedef vectorVP; templateinline bool mina(A &x,const B &y){return(yinline bool maxa(A &x,const B &y){return(x class ModInt { public: Int x; ModInt(): x(0) {} ModInt(int a, bool m=1) { if(m) {x=a%mod; if(x<0)x+=mod;} else x=a; } ModInt(LL a, bool m=1) { if(m) {x=a%mod; if(x<0)x+=mod;} else x=a; } inline ModInt &operator+=(ModInt that) { if((x += that.x) >= mod) x -= mod; return *this; } inline ModInt &operator-=(ModInt that) { if((x += mod - that.x) >= mod) x -= mod; return *this; } inline ModInt &operator*=(ModInt that) { x = LL(x) * that.x % mod; return *this; } inline ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } inline ModInt operator-() const { return ModInt(-this->x); } ModInt inverse() const {LL a=x,b=mod,u=1,v=0;while(b){LL t=a/b;a-=t*b;u-=t*v;swap(a,b);swap(u,v);} return ModInt(u);} inline friend ostream& operator << (ostream &out, ModInt m) {return out << m.x;} #define op(o1,o2) ModInt operator o1(ModInt that) const { return ModInt(*this) o2 that; } op(+,+=) op(-,-=) op(*,*=) op(/,/=) #undef op #define op(o) bool operator o(ModInt that) const { return x o that.x; } op(==) op(!=) op(<) op(<=) op(>) op(>=) #undef op }; const int moder = 1e9+7; typedef ModInt Mint; #define MAXN (1204) int A[MAXN]; int B[MAXN][MAXN]; Mint dp[MAXN][MAXN]; Mint F[MAXN]; Mint FI[MAXN]; int main() { IO(); cint1(N); F[0] = FI[0] = 1; FOR(i,1,N+1) { F[i] = F[i-1] * i; FI[i] = F[i].inverse(); } FOR(i,0,N) cin >> A[i]; FOR(i,0,N) { FOR(j,i,N) { if(j != i && A[j-1] > A[j]) break; B[i][j] = 1; } } FOR(n,1,N+1) FOR(k,1,n+1) if(B[N-n][N-n+k-1]) { Mint res; if(n == k) res = 1; else { FOR(i,1,min(k,n-k)+1) res += dp[n-k][i] * FI[k-i]; res *= F[k]; } dp[n][k] = res; } Mint sol; FOR(k,1,N+1) sol += dp[N][k]; cout << sol << nl; return 0; }