atcoder#AGC053E. [AGC053E] More Peaks More Fun
[AGC053E] More Peaks More Fun
Score : points
Problem Statement
We have cards and boxes. The cards are numbered through , and the boxes are numbered through . Each box contains two cards; Box contains Card and Card .
Find, modulo , the number of ways to arrange the boxes in a row that satisfies the following condition.
- Consider getting a sequence of cards as follows: for each box, from left to right, open it and append the two cards in it to the end of the sequence in an order we like. In this way, it is possible to get a sequence with peaks.
Here, a peak in a sequence is an integer satisfying such that and .
Constraints
- are pairwise distinct.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
1 3
2 4
5 6
4
For example, if we arrange Boxes in this order, we can arrange the cards as follows to get a sequence with peaks:
- first, arrange the cards in Box in the order ;
- next, append the cards in Box at the end in the order ;
- lastly, append the cards in Box at the end in the order .
Here, we have with peaks .
6
5 8
7 2
1 3
11 6
4 12
9 10
492
10
20 15
8 5
6 7
4 9
13 1
11 14
10 17
19 12
3 16
2 18
1411200