Educational Codeforces Round 108 (Rated for Div. 2)


A. Red and Blue Beans
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1 0
2 7 3
6 1 4
5 4 0
Output
YES
YES
NO
NO
----------------------------------------------------------------------------------------------------
B. The Cake Is a Lie
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1 1 0
2 2 2
2 2 3
2 2 4
1 4 3
100 100 10000
Output
YES
NO
YES
NO
YES
NO
----------------------------------------------------------------------------------------------------
C. Berland Regional
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
7
1 2 1 2 1 2 1
6 8 3 1 5 1 5
10
1 1 1 2 2 2 2 3 3 3
3435 3014 2241 2233 2893 2102 2286 2175 1961 2567
6
3 3 3 3 3 3
5 9 6 7 9 7
1
1
3083
Output
29 28 26 19 0 0 0 
24907 20705 22805 9514 0 0 0 0 0 0 
43 43 43 32 38 43 
3083 
----------------------------------------------------------------------------------------------------
D. Maximum Sum of Products
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 3 2 1 3
1 3 2 4 2
Output
29
Input
2
13 37
2 4
Output
174
Input
6
1 8 7 6 3 6
5 9 6 8 8 6
Output
235
----------------------------------------------------------------------------------------------------
E. Off by One
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
4 1 5 1
1 1 1 1
3 3 3 3
1 1 4 1
6 1 1 1
5 1 4 1
6 1 1 1
Output
3
1 6
2 4
5 7
Input
4
2 1 1 1
1 1 2 1
2 1 1 2
1 2 1 2
Output
1
1 2
Input
4
182 168 60 96
78 72 45 72
69 21 144 63
148 12 105 6
Output
1
2 4
----------------------------------------------------------------------------------------------------
F. Chests and Keys
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 3
3 3
1 1 4
10 20 100
20 15 80
Output
205
Input
2 3
3 3
2 1 4
10 20 100
20 15 80
Output
110
Input
2 3
3 4
1 1 4
10 20 100
20 15 80
Output
-1
----------------------------------------------------------------------------------------------------
