#include #define fi first #define se second #define sc scanf #define pr printf #define pb push_back #define ll long long #define fin(s) freopen( s, "r", stdin ); #define fout(s) freopen( s, "w", stdout ); const int N = 1222; const int MX = 300300; const long long mod = 1e9 + 7; using namespace std; ll n; ll a[N]; ll f[N][N]; ll d[N][N]; bool can[N][N]; void solve() { for(ll i = 0; i < N; i++){ f[i][i] = max(i, 1ll); for(ll j = i + 1; j < N; j++) f[i][j] = f[i][j - 1] * j % mod; for(ll j = 0; j < i; j++) f[i][j] = 1; } cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++){ can[i][i] = true; for(int j = i + 1; j <= n; j++){ if(a[j] > a[j - 1]) can[i][j] = true; else break; } } d[n + 1][0] = 1; for(int i = n; i >= 1; i--){ for(int j = 0; j < N && i - j >= 0; j++){ if(d[i + 1][j] == 0) continue; for(int h = max(1, j); i - h >= 0 && can[i - h + 1][i]; h++) d[i - h + 1][h] = (d[i - h + 1][h] + d[i + 1][j] * f[h - j + 1][h]) % mod; } } //cout << d[1][2] << endl; ll ans = 0; for(int i = 1; i < N; i++) ans = (ans + d[1][i]) % mod; cout << ans << endl; } bool mtest = false; int main() { //fin("input.txt"); //fout("output.txt"); //fin("friendcross.in"); //fout("friendcross.out"); ios_base::sync_with_stdio(0); int TE = 1; if(mtest) cin >> TE; while(TE--) solve(); }