問題
Moo! You are given an integer
You are additionally given
入力
The first line contains
Each test case starts with
The same
出力
For each test case, the answer modulo
部分問題
| 番号 | 点数 | 条件 |
|---|---|---|
| #1 | 10点 | |
| #2 | 20点 | |
| #3 | 20点 | For all test cases, the constraint |
| #4 | 20点 | For all test cases, there exists some constraint |
| #5 | 30点 | No additional constraints. |
例題 #1
3 4
0
1
1 1
2
0 2
2 3
2
0
1
The maximum possible value of
例題 #2
9 11
2
0 5
6 9
3
0 5
6 9
1 0
4
0 5
6 9
1 0
4 7
5
0 5
6 9
1 0
4 7
2 6
6
0 5
6 9
1 0
4 7
2 6
9 3
7
0 5
6 9
1 0
4 7
2 6
9 3
5 2
8
0 5
6 9
1 0
4 7
2 6
9 3
5 2
7 4
9
0 5
6 9
1 0
4 7
2 6
9 3
5 2
7 4
3 1
10
0 5
6 9
1 0
4 7
2 6
9 3
5 2
7 4
3 1
8 10
6
6
1
1
1
1
1
1
1
例題 #3
10 11
0
1
3 8
2
3 8
5 7
3
3 8
5 7
4 2
4
3 8
5 7
4 2
10 6
5
3 8
5 7
4 2
10 6
8 10
6
3 8
5 7
4 2
10 6
8 10
1 9
7
3 8
5 7
4 2
10 6
8 10
1 9
7 5
8
3 8
5 7
4 2
10 6
8 10
1 9
7 5
2 3
9
3 8
5 7
4 2
10 6
8 10
1 9
7 5
2 3
6 0
160
20
8
7
2
1
1
1
1
1
例題 #4
5 987
3
654 321
543 210
432 106
2
654 321
543 210
1
654 321
1
0 493
0
0
538184948
693625420
932738155
251798971
Make sure to output the answer modulo