atcoder#ARC093D. [ARC093F] Dark Horse
[ARC093F] Dark Horse
Score : points
Problem Statement
There are players, numbered . They decided to hold a tournament.
The tournament proceeds as follows:
- Choose a permutation of : .
- The players stand in a row in the order of Player , Player , , Player .
- Repeat the following until there is only one player remaining in the row:- Play the following matches: the first player in the row versus the second player in the row, the third player versus the fourth player, and so on. The players who lose leave the row. The players who win stand in a row again, preserving the relative order of the players.
- Play the following matches: the first player in the row versus the second player in the row, the third player versus the fourth player, and so on. The players who lose leave the row. The players who win stand in a row again, preserving the relative order of the players.
- The last player who remains in the row is the champion.
It is known that, the result of the match between two players can be written as follows, using integers given as input:
- When for some , the winner of the match between Player and Player () will be Player .
- When for every , the winner of the match between Player and Player () will be Player .
- When , the winner of the match between Player and Player will be Player .
The champion of this tournament depends only on the permutation chosen at the beginning. Find the number of permutation chosen at the beginning of the tournament that would result in Player becoming the champion, modulo .
Constraints
- ()
- ()
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2 1
3
8
Examples of that satisfy the condition are: and . Examples of that do not satisfy the condition are: and .
4 3
2 4 6
0
3 0
40320
3 3
3 4 7
2688
16 16
5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003
816646464