Codeforces Round 377 (Div. 2)


A. Buy a Shovel
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
117 3
Output
9
Input
237 7
Output
1
Input
15 2
Output
2
----------------------------------------------------------------------------------------------------
B. Cormen — The Best Friend Of a Man
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
----------------------------------------------------------------------------------------------------
D. Exams
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 2
0 1 0 2 1 0 2
2 1
Output
5
Input
10 3
0 0 1 2 3 0 2 0 1 2
1 1 4
Output
9
Input
5 1
1 1 1 1 1
5
Output
-1
----------------------------------------------------------------------------------------------------
E. Sockets
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
1 1
2 2
Output
2 2
1 1
1 2
Input
2 1
2 100
99
Output
1 6
6
1 0
----------------------------------------------------------------------------------------------------
F. Tourist Reform
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 9
4 3
2 6
7 1
4 1
7 3
3 5
7 4
6 5
2 5
Output
4
4 3
6 2
7 1
1 4
3 7
5 3
7 4
5 6
2 5
----------------------------------------------------------------------------------------------------
