#include using namespace std; typedef long long ll; typedef pair pii; typedef vector vi; #define pb push_back #define mp make_pair #define FOR(i, a, b) for (int i=a; i= MOD) { s -= MOD; } return s; } int mult(int a, int b) { return ((ll)a*(ll)b)%MOD; } int sq(int a) { return mult(a, a); } int pow(int a, int b) { if (b == 0) { return 1; } if (b%2 == 0) { return sq(pow(a, b/2)); } else { return mult(a, sq(pow(a, b/2))); } } int f[MAX], fi[MAX]; void init() { f[0] = fi[0] = 1; FOR(i, 1, MAX) { f[i] = mult(f[i-1], i); fi[i] = pow(f[i], MOD-2); } } int perm(int a, int b) { return mult(f[a], fi[a-b]); } int a[MAX], dp[MAX]; int ans[MAX][MAX]; int n; int fx(int m, int k) { if (m > n) { return 1; } if (ans[m][k] != -1) { return ans[m][k]; } int tot = 0; FOR(i, 1, k+1) { if (i > dp[m]) { break; } tot = add(tot, mult(perm(k, i), fx(m+i, i))); } ans[m][k] = tot; return tot; } int main() { init(); F0R(i, MAX) { F0R(j, MAX) { ans[i][j] = -1; } } scanf("%d", &n); FOR(i, 1, n+1) { scanf("%d", &a[i]); } for (int i=n; i>=1; i--) { dp[i] = dp[i+1] + 1; if (i != n && a[i] > a[i+1]) { dp[i] = 1; } } int fin = 0; FOR(i, 1, dp[1]+1) { fin = add(fin, fx(1+i, i)); } printf("%d\n", fin); }