atcoder#AGC054B. [AGC054B] Greedy Division
[AGC054B] Greedy Division
Score : points
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 .
- 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.
3
1 1 2
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.
4
1 2 3 8
0
20
2 8 4 7 5 3 1 2 4 1 2 5 4 3 3 8 1 7 8 2
373835282