Educational Codeforces Round 126 (Rated for Div. 2)


A. Array Balancing
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
3 3 10 10
10 10 3 3
5
1 2 3 4 5
6 7 8 9 10
6
72 101 108 108 111 44
10 87 111 114 108 100
Output
0
8
218
----------------------------------------------------------------------------------------------------
B. Getting Zero
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
19 32764 10240 49
Output
14 4 4 15 
----------------------------------------------------------------------------------------------------
C. Water the Trees
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3
1 2 4
5
4 4 3 5 5
7
2 5 4 8 3 7 4
Output
4
3
16
----------------------------------------------------------------------------------------------------
D. Progressions Covering
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
5 4 6
Output
5
Input
6 3
1 2 3 2 2 3
Output
3
Input
6 3
1 2 4 1 2 3
Output
3
Input
7 3
50 17 81 25 42 39 96
Output
92
----------------------------------------------------------------------------------------------------
E. Narrow Components
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
12
100101011101
110110010110
010001011101
8
1 12
1 1
1 2
9 9
8 11
9 12
11 12
4 6
Output
7
1
1
2
1
3
3
3
----------------------------------------------------------------------------------------------------
F. Teleporters
time limit per test: 7 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2
1 5
7
Output
2
Input
2
1 5
6
Output
3
Input
1
5
5
Output
4
Input
1
1000000000
1000000043
Output
999999978
----------------------------------------------------------------------------------------------------
