QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 128 MB 満点: 100

#16026. Mingming's Trouble

統計

Ever since Mingming learned about tree structures, he has developed a keen interest in trees of all shapes and sizes. After drawing many different trees, he came up with a question: given $n$ nodes labeled from $1$ to $n$, and allowing arbitrary connections between any two nodes, how many different trees with $n$ nodes can be formed in total? While working on this problem, he thought of another, more general question: given $n$ nodes labeled from $1$ to $n$ and the required degrees for some of these nodes, and allowing arbitrary connections between any two nodes, how many different trees with $n$ nodes can be formed such that the degrees of the nodes satisfy the given requirements?

Mingming pondered this for a long time but could only manually calculate a few simple cases. As a beginner in programming, he does not know how to write a program to solve this problem. Therefore, he is turning to you, who are preparing for NOI2008, to help him solve it.

Input

The first line contains an integer $n$, representing the number of nodes in the tree. The next $n$ lines represent the required degrees for nodes $1$ through $n$ respectively. The $(i+1)$-th line represents the required degree $D_i$ for node $i$. If the value is $-1$, it means there is no requirement for the degree of node $i$. The input data guarantees $0 < n \le 1000$ and $-1 \le D_i < n$.

Output

Contains a single integer representing the number of different trees that can be drawn. If there is no solution, output $0$.

Examples

Input 1

3
1
-1
-1

Output 1

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.