#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define pb push_back #define mp make_pair #define rep(i,a,b) for(int i=a;i<=b;i++) #define ren(i,a,b) for(int i=a;i>=b;i--) #define ff first #define ss second #define pll pair #define pii pair #define vll vector #define vii vector #define gi(n) scanf("%d",&n) #define gll(n) scanf("%lld",&n) #define gstr(n) scanf("%s",n) #define gl(n) cin >> n #define oi(n) printf("%d",n) #define oll(n) printf("%lld",n) #define ostr(n) printf("%s",n) #define ol(n) cout << n #define os cout<<" " #define on cout<<"\n" #define o2(a,b) cout< > mat; ll dp[2005][2005]; ll m=1e9+7,f[200005],inv[200005]; ll p(ll a,ll b) { ll r=1; while(b) { if(b&1) r=(r*a)%m; a=(a*a)%m; b/=2; } return r; } ll ncr(ll n,ll r) { if(r>n||r<0) return 0; ll k=(inv[n-r]); k=(f[n]*k); if(k>=m)k%=m; return k; } int main() {ios_base::sync_with_stdio(false); int n,a[2005]; cin>>n; rep(i,1,n)cin>>a[i]; f[0]=1; rep(i,1,200004) f[i]=(f[i-1]*i)%m; inv[200004]=p(f[200004],m-2); ren(i,200003,0) inv[i]=(inv[i+1]*(i+1))%m; rep(i,1,n) { ren(j,i,1) { if(j!=i&&a[j]>a[j+1])break; int k=i-j+1; if(j==1)dp[i][k]++; else { rep(l,k,j-1) { dp[i][k]=(dp[i][k]+dp[j-1][l]*ncr(l,k)); if(dp[i][k]>=m)dp[i][k]%=m; } } //o2(i,k);os;ol(dp[i][k]);on; } } ll ans=0; rep(i,0,2004) ans=(ans+dp[n][i])%m; ol(ans); return 0; }