Codeforces Round 709 (Div. 1, based on Technocup 2021 Final Round)


A. 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
----------------------------------------------------------------------------------------------------
B. 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 
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. 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
----------------------------------------------------------------------------------------------------
E. 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
----------------------------------------------------------------------------------------------------
F. 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
----------------------------------------------------------------------------------------------------
