Технокубок 2021 - Финал


A. Prison Break
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 2
1 3
Output
4
3
----------------------------------------------------------------------------------------------------
B. Restore Modulo
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
6
1 9 17 6 14 3
3
4 2 2
3
7 3 4
3
2 2 4
5
0 1000000000 0 1000000000 0
2
1 1
Output
19 8
-1
-1
-1
2000000000 1000000000
0
----------------------------------------------------------------------------------------------------
C. Basic Diplomacy
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2
4 6
1 1
2 1 2
3 1 2 3
4 1 2 3 4
2 2 3
1 3
2 2
1 1
1 1
Output
YES
1 2 1 1 2 3 
NO
----------------------------------------------------------------------------------------------------
D. Playlist
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
5 9 2 10 15
6
1 2 4 2 4 2
2
1 2
1
1
1
2
Output
2 2 3 
2 2 1 
2 2 1 
1 1 
0 
----------------------------------------------------------------------------------------------------
E. Skyline Photo
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 3 5 4
1 5 3 2 4
Output
15
Input
5
1 4 3 2 5
-3 4 -10 2 7
Output
10
Input
2
2 1
-2 -3
Output
-3
Input
10
4 7 3 2 5 1 9 10 6 8
-4 40 -46 -8 -16 4 -10 41 12 3
Output
96
----------------------------------------------------------------------------------------------------
F. Useful Edges
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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

Examples
Input
1
Lucky!
Lucky!
Lucky!
Lucky!
Lucky!
Fraudster!
Output
? 1
? 2
? 3
? 4
? 5
? 6
! 5
----------------------------------------------------------------------------------------------------
H. Exam
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
hidan
dan
hanabi
bi
nabi
Output
3
Input
4
abacaba
abaca
acaba
aca
Output
4
----------------------------------------------------------------------------------------------------
