Codeforces Round 592 (Div. 2)


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

Examples
Input
3
7 5 4 5 8
7 5 4 5 2
20 53 45 26 4
Output
7 1
-1
1 3
----------------------------------------------------------------------------------------------------
B. Rooms and Staircases
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5
00100
8
00000000
5
11111
3
110
Output
6
8
10
6
----------------------------------------------------------------------------------------------------
C. The Football Season
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
30 60 3 1
Output
17 9 4
Input
10 51 5 4
Output
-1
Input
20 0 15 5
Output
0 0 20
----------------------------------------------------------------------------------------------------
D. Paint the Tree
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 2 3
4 3 2
3 1 3
1 2
2 3
Output
6
1 3 2 
Input
5
3 4 2 1 2
4 2 1 5 4
5 3 2 1 1
1 2
3 2
4 3
5 3
Output
-1
Input
5
3 4 2 1 2
4 2 1 5 4
5 3 2 1 1
1 2
3 2
4 3
5 4
Output
9
1 3 2 1 3 
----------------------------------------------------------------------------------------------------
E. Minimizing Difference
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5
3 1 7 5
Output
2
Input
3 10
100 100 100
Output
0
Input
10 9
4 5 5 7 5 4 5 2 4 3
Output
1
----------------------------------------------------------------------------------------------------
F. Chips
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 1
BWBBWW
Output
WBBBWW
Input
7 3
WBWBWBW
Output
WWWWWWW
Input
6 4
BWBWBW
Output
BWBWBW
----------------------------------------------------------------------------------------------------
G. Running in Pairs
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 20
Output
20
1 2 3 4 5 
5 2 4 3 1 
Input
3 9
Output
8
1 2 3 
3 2 1 
Input
10 54
Output
-1
----------------------------------------------------------------------------------------------------
