#agc054b. [agc054_b]Greedy Division
[agc054_b]Greedy Division
Problem Statement
We have oranges, numbered through . The weight of Orange is . Takahashi and Aoki will share these oranges as follows.
-
Choose a permutation of .
-
For each in this order, do the following.
- If the total weight of the oranges Takahashi has taken is not greater than that of the oranges Aoki has taken, Takahashi takes Orange . Otherwise, Aoki takes Orange .
Find the number of permutations modulo such that the total weight of the oranges Takahashi will take is equal to that of the oranges Aoki will take.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 1 2
Sample Output 1
4
There are four permutations satisfying the condition: . If , for example, the following will happen.
- : the total weights of the oranges Takahashi and Aoki have taken are and , respectively. Takahashi takes Orange .
- : the total weights of the oranges Takahashi and Aoki have taken are and , respectively. Aoki takes Orange .
- : the total weights of the oranges Takahashi and Aoki have taken are and , respectively. Aoki takes Orange .
Thus, the permutation counts.
Sample Input 2
4
1 2 3 8
Sample Output 2
0
Sample Input 3
20
2 8 4 7 5 3 1 2 4 1 2 5 4 3 3 8 1 7 8 2
Sample Output 3
373835282