Codeforces Round 707 (Div. 2, based on Moscow Open Olympiad in Informatics)


A. Alexey and Train
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2
2 4
10 12
0 2
5
1 4
7 8
9 10
13 15
19 20
1 2 3 4 5
Output
12
32
----------------------------------------------------------------------------------------------------
B. Napoleon Cake
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
6
0 3 0 0 1 3
10
0 0 0 1 0 5 0 0 0 2
3
0 0 0
Output
1 1 0 1 1 1 
0 1 1 1 1 1 0 0 1 1 
0 0 0 
----------------------------------------------------------------------------------------------------
C. Going Home
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2 1 5 2 7 4
Output
YES
2 3 1 6 
Input
5
1 3 1 9 20
Output
NO
----------------------------------------------------------------------------------------------------
D. Two chandeliers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2 4
4 2 3 1
2 1
Output
5
Input
3 8 41
1 3 2
1 6 4 3 5 7 2 8
Output
47
Input
1 2 31
1
1 2
Output
62
----------------------------------------------------------------------------------------------------
E. Matrix Sorting
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
2 2
1 2
1 2
2 2
Output
1
1
Input
3 3
2 3 2
1 3 3
1 1 2
1 1 2
1 3 3
2 3 2
Output
2
1 2
Input
2 2
1 1
2 1
2 1
1 1
Output
-1
Input
4 1
2
2
2
1
1
2
2
2
Output
1
1 
----------------------------------------------------------------------------------------------------
F. Tiles for Bathroom
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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