Codeforces Round 623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)


A. Dead Pixel
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
----------------------------------------------------------------------------------------------------
B. Homecoming
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 2 1
BB
1 1 1
AB
3 2 8
AABBBBAABB
5 3 4
BBBBB
2 1 1
ABABAB
Output
2
1
3
1
6
----------------------------------------------------------------------------------------------------
C. Restoring Permutation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1
1
2
4 1
3
4 1 3
4
2 3 4 5
5
1 5 7 2 8
Output
1 2 
-1
4 5 1 2 3 6 
-1
1 3 5 6 7 9 2 4 8 10 
----------------------------------------------------------------------------------------------------
D. Recommendations
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
3 7 9 7 8
5 2 5 7 5
Output
6
Input
5
1 2 3 4 5
1 1 1 1 1
Output
0
----------------------------------------------------------------------------------------------------
E. Double Elimination
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 1
6
Output
6
Input
3 3
1 7 8
Output
11
Input
3 4
1 3 5 7
Output
14
----------------------------------------------------------------------------------------------------
F. Au Pont Rouge
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 2 1
abac
Output
aba
Input
19 5 1821
aupontrougevkoffice
Output
au
----------------------------------------------------------------------------------------------------
