Educational Codeforces Round 158 (Rated for Div. 2)


A. Line Trip
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 7
1 2 5
3 6
1 2 5
1 10
7
Output
4
3
7
----------------------------------------------------------------------------------------------------
B. Chip and Ribbon
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4
1 2 2 1
5
1 0 1 0 1
5
5 4 3 2 1
1
12
Output
1
2
4
11
----------------------------------------------------------------------------------------------------
C. Add, Divide and Floor
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
10
2
4 6
6
2 1 2 1 2 1
2
0 32
Output
0
2
2 5
1
1
6
----------------------------------------------------------------------------------------------------
D. Yet Another Monster Fight
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2 1 5 6 4 3
Output
8
Input
5
4 4 4 4 4
Output
8
Input
2
1 1000000000
Output
1000000000
----------------------------------------------------------------------------------------------------
E. Compressed Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
1 -2 2 1
1 2
3 2
2 4
2
-2 -5
2 1
7
-2 4 -2 3 3 2 -1
1 2
2 3
3 4
3 5
4 6
4 7
Output
3
0
9
----------------------------------------------------------------------------------------------------
F. Landscaping
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
0 5 1 3 0
0 1 3 2 0
Output
8.000000000000 4.000000000000 6.000000000000 6.000000000000 6.000000000000
Input
6
0 4 1 3 3 0
0 1 4 0 1 0
Output
7.000000000000 5.000000000000 7.500000000000 7.500000000000 6.666666666667 6.666666666667
----------------------------------------------------------------------------------------------------
