Codeforces Global Round 5


A. Balanced Rating Changes
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
10
-5
-5
Output
5
-2
-3
Input
7
-7
-29
0
3
24
-29
38
Output
-3
-15
0
2
12
-15
19
----------------------------------------------------------------------------------------------------
B. Balanced Tunnel
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
3 5 2 1 4
4 3 2 5 1
Output
2
Input
7
5 2 3 6 7 1 4
2 3 6 7 1 4 5
Output
6
Input
2
1 2
1 2
Output
0
----------------------------------------------------------------------------------------------------
C1. Balanced Removals (Easier)
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
3 1 0
0 3 0
2 2 0
1 0 0
1 3 0
0 1 0
Output
3 6
5 1
2 4
Input
8
0 1 1
1 0 1
1 1 0
1 1 1
2 2 2
3 2 2
2 3 2
2 2 3
Output
4 5
1 6
2 7
3 8
----------------------------------------------------------------------------------------------------
C2. Balanced Removals (Harder)
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
3 1 0
0 3 0
2 2 0
1 0 0
1 3 0
0 1 0
Output
3 6
5 1
2 4
Input
8
0 1 1
1 0 1
1 1 0
1 1 1
2 2 2
3 2 2
2 3 2
2 2 3
Output
4 5
1 6
2 7
3 8
----------------------------------------------------------------------------------------------------
D. Balanced Playlist
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
11 5 2 7
Output
1 1 3 2
Input
4
3 2 5 3
Output
5 4 3 6
Input
3
4 3 6
Output
-1 -1 -1
----------------------------------------------------------------------------------------------------
E. Balanced Binary Search Trees
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
Output
1
Input
3
Output
0
----------------------------------------------------------------------------------------------------
F. Balanced Domino Placements
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 7 2
3 1 3 2
4 4 4 5
Output
8
Input
5 4 2
1 2 2 2
4 3 4 4
Output
1
Input
23 42 0
Output
102848351
----------------------------------------------------------------------------------------------------
G. Balanced Distribution
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 3
2 6 1 10 3 2
Output
3
2 7 3 4
5 4 4 2
1 4 4 4
Input
11 4
1 0 1 0 0 4 4 2 4 3 3
Output
3
3 2 2 2 2
8 2 2 2 5
10 2 2 2 2
----------------------------------------------------------------------------------------------------
H. Balanced Reversals
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
0100011011
1101011000
10101010
10101010
0011
1001
100011
110010
Output
3
6 4 10
0
-1
7
2 6 2 6 2 2 6
----------------------------------------------------------------------------------------------------
