#abc295e. [abc295_e]Kth Number
[abc295_e]Kth Number
Problem Statement
We have a sequence of length consisting of integers between and , inclusive: .
Snuke will perform the following operations 1 and 2 in order.
- For each such that , independently choose a uniform random integer between and , inclusive, and replace with that integer.
- Sort in ascending order.
Print the expected value of after the two operations, modulo .
How to print a number modulo ? It can be proved that the sought expected value is always rational. Additionally, under the Constraints of this problem, when that value is represented as using two coprime integers and , it can be proved that there is a unique integer such that and . Print this .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the expected value of after the two operations, modulo .
Sample Input 1
3 5 2
2 0 4
Sample Output 1
3
In the operation 1, Snuke will replace with an integer between and . Let be this integer.
- If or , we will have after the two operations.
- If , we will have after the two operations.
- If or , we will have after the two operations.
Thus, the expected value of is .
Sample Input 2
2 3 1
0 0
Sample Output 2
221832080
The expected value is .
Sample Input 3
10 20 7
6 5 0 2 0 0 0 15 0 0
Sample Output 3
617586310