Manthan, Codefest 18 (rated, Div. 1 + Div. 2)


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

Examples
Input
6
Output
3
Input
2
Output
2
----------------------------------------------------------------------------------------------------
B. Reach Median
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 8
6 5 8
Output
2
Input
7 20
21 15 12 11 20 19 12
Output
6
----------------------------------------------------------------------------------------------------
C. Equalize
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
100
001
Output
2
Input
4
0101
0011
Output
1
----------------------------------------------------------------------------------------------------
D. Valid BFS?
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2
1 3
2 4
1 2 3 4
Output
Yes
Input
4
1 2
1 3
2 4
1 2 4 3
Output
No
----------------------------------------------------------------------------------------------------
E. Trips
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4 2
2 3
1 2
1 3
1 4
Output
0
0
3
3
Input
5 8 2
2 1
4 2
5 4
5 2
4 3
5 1
4 1
3 2
Output
0
0
0
3
3
4
4
5
Input
5 7 2
1 5
3 2
2 5
3 4
1 2
5 3
1 3
Output
0
0
0
0
3
4
4
----------------------------------------------------------------------------------------------------
F. Maximum Reduction
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
9 1 10
Output
29
Input
5 3
5 8 7 1 9
Output
34
----------------------------------------------------------------------------------------------------
G. A Game on Strings
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
aaab
2
1 2
1 4
Output
Alice
Bob
Input
aaccbdb
2
5 7
1 7
Output
Alice
Alice
----------------------------------------------------------------------------------------------------
H. Security
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
baa
5
1 2 ba
2 3 a
1 2 b
2 3 aa
1 3 b
Output
-1
aa
ba
-1
ba
Input
bacb
4
1 2 ba
2 3 ac
1 3 ac
3 4 c
Output
-1
c
b
cb
Input
bba
1
1 1 b
Output
-1
----------------------------------------------------------------------------------------------------
