Educational Codeforces Round 95 (Rated for Div. 2)


A. Buying Torches
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 1 5
42 13 24
12 11 12
1000000000 1000000000 1000000000
2 1000000000 1000000000
Output
14
33
25
2000000003
1000000001999999999
----------------------------------------------------------------------------------------------------
B. Negative Prefixes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
1 3 2
0 0 0
4
2 -3 4 -1
1 1 1 1
7
-8 4 -2 -6 4 7 1
1 0 0 0 1 1 0
5
0 1 -4 6 3
0 0 0 1 1
6
-1 7 10 4 -8 -1
1 0 0 0 0 1
Output
1 2 3
2 -3 4 -1
-8 -6 1 4 4 7 -2
-4 0 1 6 3
-1 4 7 -8 10 -1
----------------------------------------------------------------------------------------------------
C. Mortal Kombat Tower
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
8
1 0 1 1 0 1 1 1
5
1 1 1 1 0
7
1 1 1 1 0 0 1
6
1 1 1 1 1 1
1
1
1
0
Output
2
2
2
2
1
0
----------------------------------------------------------------------------------------------------
D. Trash Problem
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 6
1 2 6 8 10
1 4
1 9
0 6
0 10
1 100
1 50
Output
5
7
7
5
4
8
49
Input
5 8
5 1 2 4 3
0 1
0 2
0 3
0 4
0 5
1 1000000000
1 1
1 500000000
Output
3
2
1
0
0
0
0
0
499999999
----------------------------------------------------------------------------------------------------
E. Expected Damage
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 3 1
2 1
1 2
Output
665496237
1
Input
3 3
4 2 6
3 1
1 2
2 3
Output
0
8
665496236
----------------------------------------------------------------------------------------------------
F. Equal Product
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 20
91 100
Output
-1
-1
-1
-1
-1
6 16 8 12
-1
-1
Input
4 5
1 10
Output
1 2 2 1
2 3 3 2
-1
-1
Input
5 12
16 60
Output
-1
2 9 3 6
3 8 4 6
4 5 5 4
-1
----------------------------------------------------------------------------------------------------
G. Three Occurrences
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
9
1 2 2 2 1 1 2 2 2
Output
3
Input
10
1 2 3 4 1 2 3 1 2 3
Output
0
Input
12
1 2 3 4 3 4 2 1 3 4 2 1
Output
1
----------------------------------------------------------------------------------------------------
