atcoder#AGC012D. [AGC012D] Colorful Balls
[AGC012D] Colorful Balls
Score : points
Problem Statement
Snuke arranged colorful balls in a row. The -th ball from the left has color and weight .
He can rearrange the balls by performing the following two operations any number of times, in any order:
- Operation : Select two balls with the same color. If the total weight of these balls is at most , swap the positions of these balls.
- Operation : Select two balls with different colors. If the total weight of these balls is at most , swap the positions of these balls.
How many different sequences of colors of balls can be obtained? Find the count modulo .
Constraints
- are all integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4 7 3
3 2
4 3
2 1
4 4
2
- The sequence of colors can be obtained by swapping the positions of the first and third balls by operation .
- It is also possible to swap the positions of the second and fourth balls by operation , but it does not affect the sequence of colors.
1 1 1
1 1
1
21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
129729600