// vim:ts=4:sts=4:sw=4:et #include using namespace std; #define forn(i,n) for (int i = 0; i < int(n); ++i) #define sz(x) ((int) (x).size()) typedef long double ld; typedef long long ll; typedef long long i64; const int M = 1234; const int mod = 1e9 + 7; int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } int udd(int &x, int y) { return x = add(x, y); } int mul(ll x, ll y) { return x * y % mod; } int n, a[M]; int d[M][M], c[M][M], fact[M]; void pre() { for (int i = 0; i < M; ++i) c[i][0] = 1; for (int i = 1; i < M; ++i) for (int j = 1; j < M; ++j) c[i][j] = add(c[i - 1][j], c[i - 1][j - 1]); fact[0] = 1; for (int i = 1; i < M; ++i) fact[i] = mul(i, fact[i - 1]); } void read() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; } void kill() { for (int i = n - 1; i >= 0; --i) for (int cnt = 1; i + cnt <= n; ++cnt) { if (cnt > 1 && a[i + cnt - 2] > a[i + cnt - 1]) break; if (i + cnt == n) d[i][cnt] = 1; else { for (int t = 1; t <= cnt; ++t) udd(d[i][cnt], mul(mul(c[cnt][t], fact[t]), d[i + cnt][t])); } } int ans = 0; for (int i = 1; i <= n; ++i) udd(ans, d[0][i]); cout << ans << endl; } int main() { #ifdef LOCAL assert(freopen("e.in", "r", stdin)); #endif //ios_base::sync_with_stdio(false); // pre(); read(); kill(); }