Codeforces Round 647 (Div. 2) - Thanks, Algo Muse!


A. Johnny and Ancient Computer
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
10 5
11 44
17 21
1 1
96 3
2 128
1001 1100611139403776
1000000000000000000 1000000000000000000
7 1
10 8
Output
1
1
-1
0
2
2
14
0
-1
-1
----------------------------------------------------------------------------------------------------
B. Johnny and His Hobbies
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
4
1 0 2 3
6
10 7 14 8 3 12
2
0 2
3
1 2 3
6
1 4 6 10 11 12
2
0 1023
Output
1
4
2
-1
-1
1023
----------------------------------------------------------------------------------------------------
C. Johnny and Another Rating Drop
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
----------------------------------------------------------------------------------------------------
D. Johnny and Contribution
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2
2 3
3 1
2 1 3
Output
2 1 3
Input
3 3
1 2
2 3
3 1
1 1 1
Output
-1
Input
5 3
1 2
2 3
4 5
2 1 2 2 1
Output
2 5 1 3 4
----------------------------------------------------------------------------------------------------
E. Johnny and Grandmaster
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5 2
2 3 4 4 3
3 1
2 10 1000
4 5
0 1 1 100
1 8
89
Output
4
1
146981438
747093407
----------------------------------------------------------------------------------------------------
F. Johnny and Megan's Necklace
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
13 11
11 1
3 5
17 1
9 27
Output
3
8 7 9 10 5 6 1 2 3 4 
Input
5
13 11
11 1
3 5
17 1
7 29
Output
2
8 7 10 9 5 6 4 3 2 1 
Input
1
1 1
Output
20
2 1 
----------------------------------------------------------------------------------------------------
