#P15293. [MCO 2023] Segment Union
[MCO 2023] Segment Union
Description
There are positive integers and another positive integers .
Let be a permutation of . Initially, the entire number line is white. For each , the segment is colored black. is then defined as the total length of black segments on the number line. For example, if is colored black, then the total length of black segments is .
Find the sum of over all permutations of , modulo .
Input Format
The first line of input contains a single integer ().
The second line of input contains space-separated integers ().
The third line of input contains space-separated integers ().
Output Format
Output a single integer, the sum of over all permutations of , modulo .
3
2 6 15
1 2 4
78
1
1
7
14
4
7 2 7 2
3 2 1 2
240
7
1 1 2 9 17 26 30
4 4 4 4 4 4 4
181440
11
257869734 -413759255 671386528 312442221 -479133479 837936940 -775252592 -785229024 -306462979 685409332 62181930
987323333 202379759 242380132 464003610 240120482 288801746 7692451 552912477 795257073 629515685 667287542
862900292
9
0 0 -2000 396 727 999 999 1300 2000
26 268 268 396 561 604 883 998 999
616426169
Hint
Note
Sample 1: There are permutations of length 3. Let be the permutation.
- : the segments are , , , total length = .
- : the segments are , , , total length = .
- : the segments are , , , total length = .
- : the segments are , , , total length = .
- : the segments are , , , total length = .
- : the segments are , , , total length = .
The answer is .
Sample 2: There is only one permutation, and the only segment is . The answer is .
Sample 3: Note that there may be duplicate values. Different permutations may create the same sequence, and you should still count them multiple times (as though as they are different).
Sample 4: This fits the constraints of Subtask 1.
Sample 5: Remember to output the answer modulo .
Scoring
Subtask 1 ( points): All are equal, i.e. for all ()
Subtask 2 ( points): ,
Subtask 3 ( points): ,
Subtask 4 ( points):
Subtask 5 ( points):
Subtask 6 ( points): No additional constraints
京公网安备 11011102002149号