#include using namespace std; #define MAX 1205 #define LL long long #define MOD 1000000007 LL pang(LL a, LL b) { if (b == 1) return a; LL res = pang(a, b/2); res = (res * res)%MOD; if (b % 2 == 1) return (res * a) % MOD; return res; } LL fact[MAX]; LL invfact[MAX]; LL pre[MAX][MAX]; LL dp[MAX][MAX]; bool CON[MAX][MAX]; int n; int arr[MAX]; int base; LL f(int rem, int kotak) { if (rem == n+1) { if (base == -1) return kotak; return 1; } LL &ret = dp[rem][kotak]; if (ret != -1) return ret; ret = 0; int L = min(n-rem+1,kotak); for(int i = 1; i <= L; i++) { if (CON[rem][rem+i-1] == false) break; if (rem==1) ret = (ret + f(rem+i,i))%MOD; // nentuin awal kotak ada berapa else ret = (ret + pre[kotak-i+1][kotak]*f(rem+i,i))%MOD; //kotak! /(kotak-i)! -> pre[kotak-i+1][kotak] // if(arr[rem-i]>arr[rem-i+1])break; } return ret; } int main() { fact[0] = 1; invfact[0] = 1; for(LL i = 1; i < MAX; i++) { fact[i] = (i * fact[i-1])%MOD; invfact[i] = pang(fact[i], MOD-2); } for(int i = 0; i < MAX; i++) { for(int j = i; j < MAX; j++) { pre[i][j] = (fact[j] * invfact[max(i-1,0)])%MOD; // pre[i][j] = i*(i+1)*(i+2)*...*j! // pre[i][j] = j!/(i-1)! } } map maps; scanf("%d",&n); for(int i = 1; i <= n; i++) { scanf("%d",&arr[i]); if (maps.count(arr[i])) assert(0); maps[arr[i]]++; } for(int i = 1; i <= n; i++) { CON[i][i] = true; for(int j = i+1; j <= n; j++) { if (arr[j] < arr[j-1]) break; CON[i][j] = true; } } memset(dp,-1,sizeof(dp)); printf("%lld\n",(f(1,n)%MOD + MOD)%MOD); }