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


A. 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
----------------------------------------------------------------------------------------------------
B. 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
----------------------------------------------------------------------------------------------------
C. 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 
----------------------------------------------------------------------------------------------------
D. 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
----------------------------------------------------------------------------------------------------
E. Subset Trick
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 11
1 2 3
2 1
1 5
1 6
1 7
2 6
2 2
2 3
1 10
2 5
2 7
2 10
Output
4
1
6
12
19
13
8
2
10
3
0
0
----------------------------------------------------------------------------------------------------
F. Cupboards Jumps
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7 20
4 8 12 16 20
Output
YES
4 8 8 16 20 4 0 
Input
11 10
5 7 2 3 4 5 2 1 8
Output
YES
1 1 6 8 6 5 2 0 0 1 8 
Input
6 9
1 6 9 0
Output
NO
----------------------------------------------------------------------------------------------------
