#include #include #include #include #include #include #include #include #define debug(a) #a<<" = "<>= 1; base = base * base % MOD; } return ret; } int perm(int x, int y) { return 1LL * fact[x] * inv_fact[x - y] % MOD; } int dp(int idx, int last) { if(idx == n + 1) return 1; int &ret = mem[idx][last]; if(~ret) return ret; ret = 0; for(int i = 1; i <= last; ++i) if(sorted[idx][idx + i - 1]) ret = (ret + 1LL * perm(last, i) * dp(idx + i, i)) % MOD; return ret; } int main() { cin >> n; memset(mem, -1, sizeof mem); fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = 1LL * fact[i - 1] * i % MOD; inv_fact[n] = power(fact[n], MOD - 2); for(int i = n - 1; ~i; --i) inv_fact[i] = 1LL * inv_fact[i + 1] * (i + 1) % MOD; for(int i = 1; i <= n; ++i) cin >> arr[i]; for(int i = 1; i <= n; ++i) { sorted[i][i] = true; int j = i + 1; while(arr[j] > arr[j - 1]) sorted[i][j++] = true; } int ans = 0; for(int i = 1; i <= n; ++i) if(sorted[1][i]) ans = (ans + dp(i + 1, i)) % MOD; cout << ans << endl; return 0; }