Mail.Ru Cup 2018 Round 1


A. Elevator or Stairs?
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 1 4 4 2 1
Output
YES
Input
1 6 6 2 1 1
Output
NO
Input
4 1 7 4 1 2
Output
YES
----------------------------------------------------------------------------------------------------
B. Appending Mex
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
0 1 2 1
Output
-1
Input
3
1 0 1
Output
1
Input
4
0 1 2 239
Output
4
----------------------------------------------------------------------------------------------------
C. Candies Distribution
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
0 0 1 1 2
2 0 1 0 0
Output
YES
1 3 1 2 1
Input
4
0 0 2 0
1 1 1 1
Output
NO
Input
3
0 0 0
0 0 0
Output
YES
1 1 1
----------------------------------------------------------------------------------------------------
D. Changing Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 3 0
Output
5
Input
6 3
1 4 4 7 3 4
Output
19
----------------------------------------------------------------------------------------------------
E. Chips Puzzle
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
00 10
01 11
10 01
10 01
Output
4
2 1 1 1
1 1 1 2
1 2 2 2
2 2 2 1
Input
2 3
0 0 0
011 1 0
0 0 1
011 0 0
Output
4
2 2 1 2
1 2 2 2
1 2 1 3
1 3 1 2
----------------------------------------------------------------------------------------------------
F. Electric Scheme
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 2
2 4
4 2
4 4
Output
2
5 2 1 2
1 4 5 4
2
2 1 2 5
4 5 4 1
Input
4
2 1
3 2
2 3
1 2
Output
4
2 1 2 1
3 2 3 2
1 2 1 2
2 3 2 3
3
1 2 1 2
3 2 3 2
2 3 2 1
----------------------------------------------------------------------------------------------------
G. New Road Network
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
4 3
0011
1110
0111
3 3
011
101
110
Output
YES
1 3
2 3
3 4
NO
----------------------------------------------------------------------------------------------------
H. Epic Convolution
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2 3
0 1
0 1
Output
3
Input
3 4 1
1 1 1
1 1 1 1
Output
12
Input
2 3 3
1 2
3 4 5
Output
65652
----------------------------------------------------------------------------------------------------
