#include #include #include #include #include #define ll long long using namespace std; const ll M = 1000000007; vector fac, fac1; ll ppow(ll a, ll n){ if(n==0) return 1; if(n%2==0) return ppow((a*a)%M,n/2); return (ppow(a,n-1)*a)%M; } ll solve(vector>& r, vector& s, vector& t, vector& c, ll i, ll k, ll n){ if(i==n) return 1; if(r[i][k] == -1){ r[i][k] = 0; for(ll j=0; i+j<=c[t[i]+1] and j <= k; ++j){ r[i][k] = (r[i][k]+solve(r,s,t,c,i+j,j,n)*((fac[k]*fac1[k-j])%M))%M; } } return r[i][k]; } int main() { ll n; vector s,c,t; cin >> n; fac.push_back(1); fac1.push_back(1); while(fac.size()<=n){ fac.push_back((fac.back()*fac.size())%M); fac1.push_back(0); } fac1[n] = ppow(fac[n],M-2); for(ll i = n-1; i>=0; --i){ fac1[i] = (fac1[i+1]*(i+1))%M; } ll prev, a, l=1; cin >> prev; t.push_back(0); c.push_back(0); for(ll i = 1; i> a; if(prev>a){ c.push_back(c.back()+l); s.push_back(l); l=0; } ++l; prev = a; t.push_back(s.size()); } c.push_back(n); s.push_back(l); vector> r(n,vector (n+1,-1)); ll res = 0; for(ll i =1; i