Kotlin Heroes: Episode 2


A. Three Problems
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
3 1 4 1 5 9
Output
4 1 3 
Input
5
1 1000000000 1 1000000000 1
Output
-1 -1 -1
Input
9
10 10 11 10 10 10 10 10 1
Output
9 8 3 
----------------------------------------------------------------------------------------------------
B. Traveling Around the Golden Ring of Berland
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 0 0
Output
1
Input
3
2 0 2
Output
6
Input
5
0 3 1 3 2
Output
14
Input
5
1000000000 1000000000 1000000000 1000000000 0
Output
4999999999
----------------------------------------------------------------------------------------------------
C. Ice Cream
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 7
3 5 6
0 3 4
3 3 3
Output
31
Input
1 45000
40000 50000 100000
Output
4500000000
Input
3 100
2 10 50
50 60 16
20 21 25
Output
-1
Input
4 12
2 5 1
1 2 2
2 3 7
3 10 4
Output
35
----------------------------------------------------------------------------------------------------
D. Teams
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
12 1 2 2
1 1 2 2 2 2 2 3 3 4 6 6
Output
3
Input
14 1 1 3
3 3 1 1 9 9 2 3 6 6 3 18 3 18
Output
6
Input
1 2 3 10
1000000
Output
0
----------------------------------------------------------------------------------------------------
E. Double Permutation Inc.
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 3 2 1
Output
RBBBG
Input
3
1 1 1
Output
BBB
Input
10
3 3 2 2 5 4 1 5 4 1
Output
RGRGRRRGGG
Input
10
3 9 3 1 2 1 2 4 4 4
Output
RBGRRGGBBB
----------------------------------------------------------------------------------------------------
F. kotlinkotlinkotlinkotlin...
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
lin
kot
Output
2 1 
Input
4
linkotlinkotlinkotl
kotlin
in
kot
Output
2 4 1 3 
Input
8
i
n
tlin
o
ko
t
k
l
Output
7 4 3 5 6 8 1 2 
----------------------------------------------------------------------------------------------------
G. King's Path
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
7
2 3 2 7 1 1 3
7 1 2 3 1 2 3
1 7
4 1
2 6
2 3
2 4
5 4
Output
Yes
4
1 4 2 6 
Input
1
5
1 2 2 2 2
2 2 2 2 1
1 2
2 3
3 4
4 5
Output
Yes
5
1 2 3 4 5 
Input
3
4
10 20 10 20
20 10 20 10
1 2
1 3
1 4
2
1000000 1000000
1000000 1000000
1 2
10
4 2 2 4 2 4 1 2 3 4
4 2 4 4 3 2 1 2 4 2
5 8
6 9
10 5
1 10
7 10
3 4
5 9
3 10
2 4
Output
No
Yes
0
Yes
5
3 10 5 9 6 
----------------------------------------------------------------------------------------------------
H. Road Repair in Treeland
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3
1 2
2 3
6
1 2
1 3
1 4
1 5
1 6
7
3 1
1 4
4 6
5 1
2 4
1 7
Output
1
10 20
3
1 1 1 2 2 
2
11 11 12 13 12 13
----------------------------------------------------------------------------------------------------
I. Unusual Graph
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1 2
2 3
3 4
4 1
Output
0 1 0 1 
Input
3 0
Output
0 0 0 
----------------------------------------------------------------------------------------------------
