VK Cup 2019-2020 - Elimination Round (Engine)


A. 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
----------------------------------------------------------------------------------------------------
B. 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
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. Tourism
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 8
0 1 2 2 0
0 0 1 1 2
0 1 0 0 0
2 1 1 0 0
2 0 1 2 0
Output
2
Input
3 2
0 1 1
2 0 1
2 2 0
Output
3
----------------------------------------------------------------------------------------------------
E. Strange Function
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 1
Output
6
Input
5 6
Output
1
Input
10 1
Output
138
Input
10 2
Output
33
----------------------------------------------------------------------------------------------------
F. Bad Cryptography
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7
2 2
1 1
2 3
8 10
8 2
321321321321 2
123214213213 4356903202345442785
Output
1
1
2
4
-1
6148914691236517205
68943624821423112
----------------------------------------------------------------------------------------------------
