Mail.Ru Cup 2018 Round 2


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

Examples
Input
5 3
1 1 1 1 1
1 1 1 1 1
Output
YES
Input
5 4
1 0 0 0 1
0 1 1 1 1
Output
YES
Input
5 2
0 1 1 1 1
1 1 1 1 1
Output
NO
----------------------------------------------------------------------------------------------------
B. Alice and Hairdresser
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 7 3
1 2 3 4
0
1 2 3
0
1 1 3
0
1 3 1
0
Output
1
2
2
1
----------------------------------------------------------------------------------------------------
C. Lucky Days
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
0 2 5
1 3 5
Output
2
Input
0 1 3
2 3 6
Output
1
----------------------------------------------------------------------------------------------------
D. Refactoring
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
topforces
codecoder
Output
YES
topforces
codecoder
Input
3
bab
cac
cdc
bdb
cdc
cdc
Output
YES
a
d
Input
2
you
shal
not
pass
Output
NO
----------------------------------------------------------------------------------------------------
E. Segments on the Line
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3 2 2
3 1 3 2
1 2
2 3
4 4
Output
2
Input
5 2 1 1
1 2 3 4 5
2 4
1 5
Output
1
Input
5 3 3 5
5 5 2 1 1
1 2
2 3
3 4
Output
-1
----------------------------------------------------------------------------------------------------
F. Tree and XOR
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
1 3
Output
0
Input
3 6
1 2
1 3
Output
2
----------------------------------------------------------------------------------------------------
G. Jellyfish Nightmare
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
0 0
2 0
2 2
0 2
3
1 1 1
3 5 1
1 9 1
Output
0
Input
4 6
0 0
3 0
3 3
0 3
3
1 0 1
4 2 2
3 6 1
Output
2
Input
4 2
0 0
1 0
1 1
0 1
2
1 1 1
1 3 1
Output
2
----------------------------------------------------------------------------------------------------
