Nebius Welcome Round (Div. 1 + Div. 2)


A. Lame King
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
-4 1
4 4
0 -6
-5 -4
7 -8
Output
7
8
11
9
15
----------------------------------------------------------------------------------------------------
B. Vaccination
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
6 3 5 3
1 2 3 10 11 18
6 4 0 0
3 3 3 3 3 4
9 10 2 2
0 1 2 3 4 5 6 7 8
3 10 3 6
10 20 30
5 5 4 4
0 2 4 6 8
Output
2
3
2
3
1
----------------------------------------------------------------------------------------------------
C. Pull Your Luck
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7
5 2 1
5 2 2
10 0 100
11 7 100
3 1 1000
31 0 10
100 49 7
Output
No
Yes
Yes
Yes
No
No
No
----------------------------------------------------------------------------------------------------
D. Accommodation
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 4
0100
1100
0110
1010
1011
Output
7 10
Input
1 8
01011100
Output
3 4
----------------------------------------------------------------------------------------------------
E. Routing
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 7
1 2
2 3
3 1
4 5
5 6
4 6
2 5
Output
Yes
2 5 2 5 2 5
Input
3 2
1 2
2 3
Output
Yes
2 1 2
Input
4 4
1 3
2 3
4 1
4 2
Output
Yes
3 3 1 1
Input
6 5
1 2
2 3
3 4
4 5
5 6
Output
No
----------------------------------------------------------------------------------------------------
F. Approximate Diameter
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
9 10 8
1 2
2 3
2 4
3 5
4 5
5 6
5 7
6 8
7 8
8 9
3 4
6 7
2 8
1 9
1 6
4 9
3 9
7 1
Output
10 6 5 6 2 4 2 2 1
Input
8 7 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
1 5
3 7
2 4
4 6
6 8
8 2
5 4
2 4
3 3
1 652997 124613 653029 653029 124613 124613 124613 648901 124613 653029
Output
7 5 4 4 4 3 3 3 3 3
----------------------------------------------------------------------------------------------------
G. Flow Control
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
1 3
1 5 2
Output
10
Input
1 10
7 11 1000
Output
0
Input
2 6
1 12 1
8 20 3
Output
64
Input
3 10
1 100 1
30 60 20
40 80 6
Output
534
----------------------------------------------------------------------------------------------------
H. Code Lock
time limit per test: 7 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 10
abcabcabca
Output
19
2
Input
4 20
bcbcbcbcadadadadcbda
Output
40
2
Input
4 6
adcbda
Output
12
4
----------------------------------------------------------------------------------------------------
