//By Ralif Rakhmatullin #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ll long long #define ull unsigned long long #define mp make_pair #define S second #define ld long double #define F first #define y1 LOL #define ld long double #define pb push_back #define len length #define sz size #define beg begin const ll INF = (ll)1e18 + 123; const int inf=(int)2e9 + 123; const int mod=1e9+7; using namespace std; ll dp[1211][1211]; int n, a[1211]; ll prec[1211][1211]; bool u[1211][1211]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); //cout.tie(0); //freopen(".in","r",stdin); //freopen(".out","w",stdout); cin >> n; for(int i = 1; i <= n; i ++){ cin >> a[i]; } for(int i = 1; i <= n; i ++){ prec[i][0] = 1ll; for(int j = 1; j <= i; j ++){ prec[i][j] = (prec[i][j - 1] * (1ll * (i - j + 1) ) ) % mod; } } for(int i = 1; i <= n; i++){ if(a[i] < a[i - 1]) break; u[i + 1][i] = 1; dp[i + 1][i] = 1ll; } for(int i = 1; i <= n; i ++){ for(int j = i; j >= 1; j --){ if(!u[i][j]) continue; // cout << i << " " << j << " - " << dp[i][j] << endl; for(int k = i; k <= min(n, i + j - 1); k ++){ if(k != i && a[k] < a[k - 1]) break; u[k + 1][k - i + 1] = 1; dp[k + 1][k - i + 1] += (dp[i][j] * prec[j][k - i + 1]) % mod; dp[k + 1][k - i + 1] %= mod; } } } ll ans = 0; for(int i = 1; i <= n; i ++){ // cout << i << " : " << dp[n + 1][i] << endl; ans = (ans + dp[n + 1][i]) % mod; } cout << ans; return 0; }