Educational Codeforces Round 135 (Rated for Div. 2)


A. Colored Balls: Revisited
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3
1 1 1
1
9
2
4 7
Output
3
1
2
----------------------------------------------------------------------------------------------------
B. Best Permutation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
5
6
Output
2 1 3 4
1 2 3 4 5
4 5 1 2 3 6
----------------------------------------------------------------------------------------------------
C. Digital Logarithm
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
1
1000
4
1 2 3 4
3 1 4 2
3
2 9 3
1 100 9
10
75019 709259 5 611271314 9024533 81871864 9 3 6 4865
9503 2 371245467 6 7 37376159 8 364036498 52295554 169
Output
2
0
2
18
----------------------------------------------------------------------------------------------------
D. Letter Picking
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2
forces
abba
Output
Alice
Draw
----------------------------------------------------------------------------------------------------
E. Red-Black Pepper
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5 10
100 50
2 2
4
2 3
1 1
3 2
2 2
Output
62
112
107
-1
Input
10
3 1
2 3
1 1
2 1
6 3
1 4
4 3
1 3
5 3
5 4
10
8 10
9 3
1 4
2 5
8 3
3 5
1 6
7 2
6 7
3 1
Output
26
-1
36
30
-1
26
34
26
-1
36
----------------------------------------------------------------------------------------------------
F. Fishermen
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7
1 8 2 3 2 2 3
Output
33
Input
10
5 6 5 6 5 6 5 6 5 6
Output
165
----------------------------------------------------------------------------------------------------
G. Illumination
time limit per test: 8 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 1 1
4
3
3
2 1 5
Output
48
47
47
Input
6 1 2
4
2 5
2
1 3
Output
44
46
Input
20 1 2
11
15 7
1
8
Output
413
Input
20 3 5
5 7 18
1 6 3 10 19
5
4 17 15 8 9
Output
190431
187503
188085
189903
189708
----------------------------------------------------------------------------------------------------
