#P6735. 「Wdsr-2」环

「Wdsr-2」环

Problem Description

Kagamine Rin has a circular ring with nn points evenly placed on it, and there are mm line segments connecting these points.

Suddenly one day, all these line segments disappeared.

Rin wants to recover these line segments, but she does not remember their arrangement. She only remembers that no two of these line segments intersect.

Note: touching only at endpoints is not considered an intersection; overlapping is not considered an intersection. The sample explanation below helps to understand the definition used in this problem.

Sometimes Rin also remembers some extra information: she may tell you the number of line segments incident to each point.

Now Rin wants to know how many different arrangements satisfy her memory. Since the result may be large, you only need to output the answer modulo 10000000071000000007 (the modulus is a prime number).

Input Format

The first line contains three integers n,m,typen, m, type.

If type=1type = 1, the next line contains nn integers. The ii-th integer aia_i represents the number of line segments incident to the ii-th point. The testdata guarantees that i=1nai=2m\sum_{i=1}^n a_i = 2m.

Output Format

Output a single integer, the number of valid arrangements modulo 10000000071000000007.

4 2 0

20

4 2 1
1 1 1 1

2

Hint

Sample explanation:

Update: in the second row, the third drawing in the figure above is wrong; its vertical line should be on the right.

As shown above, there are 2020 arrangements that satisfy the requirements of Sample 1, and only the last two arrangements satisfy the requirements of Sample 2.


This problem uses bundled tests, and the Constraints follow the table below:

subtask nn\le mm\le typetype score
00 88 00 1010
11 5050
22 40004000 1515
33 88 11 1010
44 5050 1515
55 600600 2020
66 40004000

For all testdata: 2n40002 \le n \le 4000, 1m40001 \le m \le 4000, type{0,1}type \in \{0,1\}, ai0a_i \ge 0. If type=1type = 1, then it is guaranteed that i=1nai=2m\sum_{i=1}^n a_i = 2m.

Translated by ChatGPT 5