Codeforces Round 901 (Div. 1)
F
Jellyfish and OEIS
Codeforces
3500
原题
← EG →
翻译中…

Jellyfish always uses OEIS to solve math problems, but now she finds a problem that cannot be solved by OEIS:

翻译中…

Count the number of permutations $p$ of $[1, 2, \dots, n]$ such that for all $(l, r)$ such that $l \leq r \leq m_l$, the subarray $[p_l, p_{l+1}, \dots, p_r]$ is not a permutation of $[l, l+1, \dots, r]$.

翻译中…

Since the answer may be large, you only need to find the answer modulo $10^9+7$.

翻译中…

Input

翻译中…

The first line of the input contains a single integer $n$ ($1 \leq n \leq 200$) — the length of the permutation.

翻译中…

The second line of the input contains $n$ integers $m_1, m_2, \dots, m_n$ ($0 \leq m_i \leq n$).

翻译中…

Output

翻译中…

Output the number of different permutations that satisfy the conditions, modulo $10^9+7$.

翻译中…

Note

翻译中…

In the first example, $[2, 3, 1]$ and $[3, 1, 2]$ satisfies the condition.

翻译中…

样例

Input #1
3
1 2 3
Output #1
2
InputCopy OutputCopy
Input #2
5
2 4 3 4 5
Output #2
38
InputCopy OutputCopy
Input #3
5
5 1 1 1 1
Output #3
0
InputCopy OutputCopy
题目信息
题号
1874F
时间限制
2 s
内存限制
512 MB
标签
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。