Codeforces Round 198 (Div. 2)
E
Iahub and Permutations
Codeforces
2000
原题
← D→
翻译中…

Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.

翻译中…

The girl finds an important permutation for the research. The permutation contains $*n*$ distinct integers $*a*_{1}$, $*a*_{2}$, ..., $*a*_{*n*}$ $(1 ≤ *a*_{*i*} ≤ *n*)$. She replaces some of permutation elements with -1 value as a revenge.

翻译中…

When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element $*a*_{*k*}$ which has value equal to $*k*$ $(*a*_{*k*} = *k*)$. Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo $1000000007$ ($10^{9} + 7$).

翻译中…

Input

翻译中…

The first line contains integer $*n*$ ($2 ≤ *n* ≤ 2000$). On the second line, there are $*n*$ integers, representing Iahub's important permutation after Iahubina replaces some values with -1.

翻译中…

It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation.

翻译中…

Output

翻译中…

Output a single integer, the number of ways Iahub could recover his permutation, modulo $1000000007$ ($10^{9} + 7$).

翻译中…

Note

翻译中…

For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point.

翻译中…

样例

Input #1
5
-1 -1 4 3 -1
Output #1
2
InputCopy OutputCopy
题目信息
题号
340E
时间限制
1 s
内存限制
256 MB
标签
组合数学
数学

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