Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)


A. Bark to Unlock
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
ya
4
ah
oy
to
ha
Output
YES
Input
hp
2
ht
tp
Output
NO
Input
ah
1
ha
Output
YES
----------------------------------------------------------------------------------------------------
B. Race Against Time
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
12 30 45 3 11
Output
NO
Input
12 0 1 12 1
Output
YES
Input
3 47 0 4 9
Output
YES
----------------------------------------------------------------------------------------------------
C. Qualification Rounds
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 0 1
1 1 0
1 0 0
1 0 0
1 0 0
Output
NO
Input
3 2
1 0
1 1
0 1
Output
YES
----------------------------------------------------------------------------------------------------
D. Huge Strings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
01
10
101
11111
0
3
1 2
6 5
4 4
Output
1
2
0
----------------------------------------------------------------------------------------------------
E. Policeman and a Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2 2
1 3 1
1 4 1
2
4
3 1 4 1
Output
8
Input
6
1 2 3
2 3 5
3 4 1
3 5 4
2 6 3
2
3
1 3 5
Output
21
----------------------------------------------------------------------------------------------------
F. Yet Another Minimization Problem
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 3
1 1 3 3 3 2 1
Output
1
Input
10 2
1 2 1 2 1 2 1 2 1 2
Output
8
Input
13 3
1 2 2 2 1 2 1 1 1 2 2 1 1
Output
9
----------------------------------------------------------------------------------------------------
G. El Toll Caves
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 1
2 1
3 2
Output
2
500000007
777777786
----------------------------------------------------------------------------------------------------
