#include #define mod 1000000007LL #define MAX 1000000000 #define INF 10000000000000009LL #define sz 200009 #define offset 209 #define ull unsigned long long #define ll long long int #define ld long double #define fi first #define se second #define pb push_back #define ios ios::sync_with_stdio(false) #define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__) #define dbvv(v) cout << "Printing "#v << " --> \n"; for(int i=0;i \n"; for(auto i=st.begin();i!=st.end();i++) cout << *i << " "; cout << "\n"; #define dbmp(mp) cout << "Printing "#mp << " --> \n"; for(auto i=mp.begin();i!=mp.end();i++) cout << #mp"[" << i->first << "]"<< " = " << i->second << "\n"; template void ZZ(const char* name, Arg1&& arg1){std::cout << name << " = " << arg1 << std::endl;} template void ZZ(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " = " << arg1; ZZ(comma, args...); } using namespace std; /* ########################## ## Author: Viral Mehta ## ## College: BITS Pilani ## ########################## */ ll n,dp[1209][1209],modular_division[1209][1209]; vector v,fact; bool is_sorted_[1209][1209],vis[1209][1209]; void compute_fact() { fact.resize(2000); ll i; fact[0]=1; for(i=1;iv[j-1])); } } ll power(ll base,ll expo) { if(base==0) return 0LL; if(expo==0) return 1LL; if((expo&1)==0) { ll temp=power(base,(expo>>1)); return (temp*temp)%mod; } return (base*power(base,expo-1LL))%mod; } void compute_modular_division() { ll i,j; for(i=0;i<=1208;i++) { for(j=0;j<=i;j++) { modular_division[i][j]=((fact[i]%mod)*(power(fact[j],mod-2)%mod))%mod; } } } ll f(ll i,ll j) { if(i==0) { if(j!=0) return 0LL; else return 1LL; } if(j==0) { if(i!=0) return 0LL; else return 1LL; } if(is_sorted_[n-i][n-i+j-1]==0) return 0LL; if(vis[i][j]==1) return dp[i][j]; vis[i][j]=1; ll x,ret=0; for(x=0;x<=j;x++) { ll numr=j; ll denr=j-x; ll val=(f(i-j,x)*modular_division[numr][denr])%mod; ret=(ret+val)%mod; } return dp[i][j]=ret; } int main() { ios; ll i; cin>>n; v.resize(n); for(i=0;i>v[i]; compute_fact(); compute_is_sorted_(); compute_modular_division(); ll ans=0; for(i=0;i<=n;i++) ans=(ans+f(n,i))%mod; cout << ans << "\n"; return 0; }