//satyaki3794 #include #define ff first #define ss second #define pb push_back #define MOD (1000000007LL) #define LEFT(n) (2*(n)) #define RIGHT(n) (2*(n)+1) using namespace std; typedef long long ll; typedef pair ii; typedef pair iii; ll pwr(ll base, ll p, ll mod = MOD){ ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans; } ll ways[1202][1202], DP[1202][1202]; int n, arr[100005], maxlen[100002]; ll dp(int i, int len){ if(i == n+1) return 1; ll &ans = DP[i][len]; if(ans != -1) return ans; ans = 0; for(int j=1;j<=len&&j<=maxlen[i];j++){ ll temp = (ways[len][j] * dp(i+j, j)) % MOD; ans = (ans + temp) % MOD; } return ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); for(int i=1;i<=1200;i++){ ways[i][1] = i; for(int j=2;j<=i;j++) ways[i][j] = (ways[i][j-1] * (i-j+1)) % MOD; } cin>>n; for(int i=1;i<=n;i++) cin>>arr[i]; maxlen[n] = 1; for(int i=n-1;i>=1;i--) if(arr[i] < arr[i+1]) maxlen[i] = maxlen[i+1]+1; else maxlen[i] = 1; memset(DP, -1, sizeof(DP)); ll ans = 0; for(int j=1;j<=maxlen[1];j++) ans = (ans + dp(j+1, j)) % MOD; cout<