#include using namespace std; #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define ll long long #define pii pair #define pll pair #define forr(a,b,c) for(int a=b;ac;a--) #define all(v) v.begin(),v.end() #define revall(v) v.rbegin(),v.rend() #define allk(v,k) v.begin()+k,v.end() #define revallk(v,k) v.rbegin()+k,v.rend() #define allkj(v,k,j) v.begin()+k,v.end()-j #define revallkj(v,k,j) v.rbegin()+j,v.rend()-k #define ff first #define ss second ////////////////////////// non-modifiable ///////////////////////////////// #define mod 1000000007 #define eps 1e-9 #define inf INT_MAX #define infl LONG_LONG_MAX ll power(ll a,ll n) { if(a==0)return 0; if(a==1 || n==0)return 1; if(n==1)return a%mod;//can remove mod? ll t=power(a,n/2); t=t*t%mod; if(n&1)return t*a%mod; return t; } #define P (int)(2e6)+9 #define FACTORIZE 1 #define DETERMINE 2 /*int primes[P]; void sieve(int prime=2)//2->detects prime, 1->max prime in factorization { forr(i,2,P-3) { if(!primes[i]) for(int j=prime*i;j0;idx-=idx&-idx) { sum+=tree[idx]; //sum%=mod; } return sum; } ////////////////////////// MODIFIABLE ///////////////////////////////////// struct node2 { int id,val; node2() { static int ctx=1; id=ctx++; }; node2(int a,int b=0,int c=0,int d=0,int e=0,int f=0) { val=a; } }; struct comp2 { bool operator()(int a,int b) { //return a s; vector v[1], vec; set sett; typedef map Mapp; Mapp mapp; ////////////////////////// variable declarations ////////////////////////// void print()//for detailed output of [a data structure] { } void print2()//for detailed output of [a data structure] { } void input() { ios_base::sync_with_stdio(false);cin.tie(NULL); cin >> n; forr(i,1,n+1) cin >> a[i]; } void init() { // fact and invfact f[0] = 1; forr(i,1,n+1) f[i] = i * f[i-1] % mod; inv[n] = power( f[n], mod - 2 ); forrev(i,n-1,-1) inv[i] = (i+1) * inv[i+1] % mod; // calculating lengths //lengths[n+1] = 1; lengths[n] = 1; forrev(i,n-1,-1) { if( a[i] < a[i+1] ) lengths[i] = lengths[i+1] + 1; else lengths[i] = 1; } // initializing dp table memset( dp, -1, sizeof( dp ) ); } inline ll perm( ll n, ll r ) { return f[n] * inv[n-r] % mod; } ll calc( int idx, int len ) // len = y of parent { if( idx >= n ) return 1; if( dp[idx][len] != -1 ) return dp[idx][len]; dp[idx][len] = 0; int y = lengths[idx+1]; y = min( y, len ); forr(i,1,y+1) { dp[idx][len] += calc( idx+i, i ) * ( idx == 0 /*|| idx+i >= n*/ ? 1 : perm( len, i ) ); dp[idx][len] %= mod; } dp[idx][len]; //cout << "idx=" << idx << " len=" << len << " y=" << y << " dp[idx][len]=" << dp[idx][len] << endl; return dp[idx][len]; } void solve() { init(); /*forr(i,0,n+1) cout << f[i] << " "; cout << endl; forr(i,0,n+1) cout << inv[i] << " "; cout << endl; forr(i,0,n+1) cout << lengths[i] << " "; cout << endl; cout << endl; forr(i,0,n+1) cout << a[i] << " "; cout << endl; cout << endl;*/ ans = calc( 0, lengths[1] ); } void output() { cout << ans; } ///////////////////////////// my functions //////////////////////////////// int main() { input(); solve(); output(); return 0; } //// MAIN //// MAIN //// MAIN //// MAIN //// MAIN //// MAIN //// MAIN ////