#include using namespace std; typedef long long ll; typedef vector vl; typedef vector vvl; typedef pair pll; typedef vector vb; const ll oo = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-9; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define FOR(i,a,b) for (ll i = (a); i < (b); i++) #define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define xx first #define yy second #define has(c,i) ((c).find(i) != end(c)) #define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; }) const int N = 1210, MOD = 1e9+7; int a[N], comb[N][N], dp[N][N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // comb[n][k] = n * (n-1) * ... * (n-k+1) FOR(n,1,N) { comb[n][0] = 1; FOR(k,1,N) comb[n][k] = (n-k+1) * comb[n][k-1] % MOD; } ll n; cin >> n; FOR(i,0,n) cin >> a[i]; // dp[i][j] = # Mglk. alles ab i auf j Arrays aufzuteilen // = is_sorted(a[i..i+j-1]) * binom[j][k] * dp[i+j][k] dp[n][0] = 1; FORD(i,0,n) { FOR(j,1,n-i+1) { if (j > 1 && a[i+j-2] > a[i+j-1]) break; ll cur = 0; FOR(k,0,j+1) { cur += ll(comb[j][k]) * dp[i+j][k]; if (cur > 7e18) cur %= MOD; } dp[i][j] = cur % MOD; } } ll res = 0; FOR(j,1,n+1) res += dp[0][j]; cout << res % MOD << endl; }