Codeforces Round 902 (Div. 1, based on COMPFEST 15 - Final Round)


A. Helmets in Night Light
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
6 3
2 3 2 1 1 3
4 3 2 6 3 6
1 100000
100000
1
4 94
1 4 2 3
103 96 86 57
Output
16
100000
265
----------------------------------------------------------------------------------------------------
B. Effects of Anti Pimples
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
19 14 19 9
Output
265
Input
1
0
Output
0
Input
15
90000 9000 99000 900 90900 9900 99900 90 90090 9090 99090 990 90990 9990 99990
Output
266012571
----------------------------------------------------------------------------------------------------
C. Autosynthesis
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 4 2 2 3
Output
3
3 2 3
Input
3
1 2 3
Output
-1
----------------------------------------------------------------------------------------------------
D. Lexichromatography
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
8
1 3 1 2 3 2 3 3
Output
3
Input
1
265
Output
1
----------------------------------------------------------------------------------------------------
E. Ball-Stackable
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
2 5 1
1 3 0
5 4 0
1 5 1
Output
3
1 5 2
5 4 1
2 5 2
3 1 3
----------------------------------------------------------------------------------------------------
F. Indefinite Clownfish
time limit per test: 3.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
9 6
2 4 2 3 2 4 1 3 4
Output
6
Input
6 6
2 6 5 2 6 5
Output
-1
Input
5 4
1 2 3 4 5
Output
-1
----------------------------------------------------------------------------------------------------
G. Clubstep
time limit per test: 3 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
5
1 3 2 1 2
3
1 5 5
2 4 5
3 3 1
Output
15
11
0
----------------------------------------------------------------------------------------------------
