#abc262h. [abc262_h]Max Limited Sequence
[abc262_h]Max Limited Sequence
Problem Statement
Find the number, modulo , of integer sequences of length that satisfy all of the following conditions:
- for all such that .
- The maximum value of is for all such that .
Constraints
- $1 \\leq L_i \\leq R_i \\leq N \\, (1 \\leq i \\leq Q)$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 3 2
1 2 2
2 3 3
Sample Output 1
5
$A = (0, 2, 3), (1, 2, 3), (2, 0, 3), (2, 1, 3), (2, 2, 3)$ satisfy the conditions.
Sample Input 2
1 1 1
1 1 1
Sample Output 2
1
Sample Input 3
6 40000000 3
1 4 30000000
2 6 20000000
3 5 10000000
Sample Output 3
135282163