#include #include #include // #include #define gc getchar//_unlocked #define pc putchar//_unlocked #define ll long long #define ld long double #define pb push_back #define mp make_pair #define pp pair #define ppl pair #define bigint boost::multiprecision::cpp_int #define finp ios_base::sync_with_stdio(0);cin.tie(0); #define bc __builtin_popcountll #define afor(i,a,b) for(int i=a;i<=b;++i) #define bfor(i,a,b) for(int i=a;i>=b;--i) #define vi vector #define vpp vector #define vll vector using namespace std; using namespace __gnu_pbds; char putnb[20]; void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);} void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);} void scll(ll *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);} ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;} const ll mod=1e9 +7; const ll mod2=1999999973; const ll inf=1e18; const int infs=1e9 + 1000; const int N=100000; const long double PI = acos(-1); template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; int n; int m[1205]; int dp[1205][1205]; ll inv[100005]; ll fact[100005]; int main() { inv[0] = 1; afor(i,1,100000)inv[i] = fp(i,mod-2,mod); fact[0] = 1; afor(i,1,100000)fact[i] = (fact[i-1] * i)%mod; finp; cin>>n; afor(i,1,n) { cin>>m[i]; int las = infs; bfor(j,i,1) { if(m[j]>= las)break; las = m[j]; int len = i - j + 1; ll ncr = fact[len]; if(j == 1)dp[i][i] = 1; afor(jj,len,j-1) { dp[i][len]+= ((ll)dp[j-1][jj] * ncr)%mod; if(dp[i][len] >= mod)dp[i][len]-=mod; ncr*= jj + 1; if(ncr >= mod)ncr%= mod; ncr*= inv[jj + 1 - len]; if(ncr >= mod)ncr%= mod; } } } ll ans = 0; afor(i,1,n) { ans+= dp[n][i]; ans%= mod; } cout<