Codeforces Round 792 (Div. 1 + Div. 2)


A. Digit Minimization
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
12
132
487456398
Output
2
1
3
----------------------------------------------------------------------------------------------------
B. Z mod X = C
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 3 4
127 234 421
2 7 8
59 94 388
Output
12 11 4
1063 234 1484
25 23 8
2221 94 2609
----------------------------------------------------------------------------------------------------
C. Column Swapping
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 3
1 2 3
1 1 1
2 2
4 1
2 3
2 2
2 1
1 1
2 3
6 2 1
5 4 3
2 1
1
2
Output
1 1
-1
1 2
1 3
1 1
----------------------------------------------------------------------------------------------------
D. Traps
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4 4
8 7 1 4
4 1
5 10 11 5
7 5
8 2 5 15 11 2 8
6 3
1 2 3 4 5 6
1 1
7
Output
0
21
9
6
0
----------------------------------------------------------------------------------------------------
E. MEX vs DIFF
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 1
3 0 1 2
4 1
0 2 4 5
7 2
4 13 0 0 13 1337 1000000000
6 2
1 2 8 0 0 0
Output
0
1
2
0
----------------------------------------------------------------------------------------------------
F. Diverse Segments
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
7 3
1 1 2 1 3 3 5
1 4
4 5
2 4
5 2
10 1 6 14 1
4 5
2 4
4 5
5 7 5 6
2 2
1 3
2 4
3 3
3 4
7 3
2 2 2 7 8 2 2
4 4
4 4
5 5
1 1
123
1 1
Output
2
0
1
0
0
----------------------------------------------------------------------------------------------------
G. Euclid Guess
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 20
1 8 1 6 3 2 3
Output
3
19 11
15 9
3 7
Input
2 10
7 1
Output
-1
Input
2 15
1 7
Output
1
15 8
Input
1 1000000000
845063470
Output
-1
----------------------------------------------------------------------------------------------------
H. Hard Cut
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
00000
01101
0111011001011
000111100111110
Output
-1
3
1 3
4 4
5 5
8
1 2
3 3
4 4
5 6
7 7
8 10
11 12
13 13
5
1 5
6 7
8 11
12 14
15 15
----------------------------------------------------------------------------------------------------
