#include using namespace std; typedef pair ii; typedef long long ll; #define fs first #define sc second const int N = 1204; const ll mod = 1000000007; ll cc, dp[N][N], M[N]; int main(){ ll n; cin >> n; dp[n][0] = 1; for(ll i = 0; i < n; ++i) cin >> M[i]; for(ll i = n - 1; i >= 0; --i){ cc = M[i] > M[i + 1] ? 1 : cc + 1; for(ll j = 1; j <= cc; ++j){ ll p = 1; for(ll k = 0; k <= j; ++k){ (dp[i][j] += p * dp[i + j][k]) %= mod; (p *= j - k) %= mod; } } } ll ans = 0; for(ll i = 1; i <= n; ++i) (ans += dp[0][i]) %= mod; cout << ans; }