#include #include #include typedef unsigned int uint_t; const uint_t N = 1200, NA = 2048, P = 1000000007; static uint_t read_uint() { const uint_t D = 10; uint_t u = 0; do { int c = getchar_unlocked(); assert (0 <= c); u = c - '0'; } while (D <= u); for (;;) { uint_t v = getchar_unlocked() - '0'; if (D <= v) break; u = u * D + v; } return u; } static uint_t cs[N + 1][NA]; static void prepare() { for (uint_t m = 0; m <= N; m++) { uint_t v = 1; for (uint_t k = 0; k <= m; k++) { cs[m][k] = v; v = v * (uint64_t) (m - k) % P; } } } static uint_t bs[N + 1][NA]; static uint_t calc(uint_t nm, const uint_t *as) { if (nm < 2) return 1; for (uint_t m = 1; m <= nm; m++) { bs[m][m] = 1; bs[m][1] = 1; } uint_t p = 1; for (uint_t n = 1; n < nm; n++) { for (uint_t m = 1; n + m <= nm; m++) { uint_t r = 0; uint_t km = m <= p ? m : p; for (uint_t k = 1; k <= km; k++) r = (r + cs[m][k] * (uint64_t) bs[n][k]) % P; bs[n + m][m] = r; } if (as[nm - n - 1] > as[nm - n]) p = 0; p++; } uint64_t res = 0; for (uint_t k = 1; k <= p; k++) res += bs[nm][k]; return res % P; } static uint_t as[N]; int main() { prepare(); uint_t n = read_uint(); assert (0 < n && n <= N); for (uint_t i = 0; i < n; i++) { uint_t a = read_uint() - 1; assert (a < n); as[i] = a; } uint_t res = calc(n, as); printf("%u\n", res); return 0; }