Codeforces Round 637 (Div. 1) - Thanks, Ivan Belonogov!


A. Nastya and Strange Generator
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
2 3 4 5 1
1
1
3
1 3 2
4
4 2 3 1
5
1 5 2 4 3
Output
Yes
Yes
No
Yes
No
----------------------------------------------------------------------------------------------------
B. Nastya and Scoreboard
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 7
0000000
Output
8
Input
2 5
0010010
0010010
Output
97
Input
3 5
0100001
1001001
1010011
Output
-1
----------------------------------------------------------------------------------------------------
C. Nastya and Unexpected Guest
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
15 5
0 3 7 14 15
11 11
Output
45
Input
13 4
0 3 7 13
9 9
Output
-1
----------------------------------------------------------------------------------------------------
D. Nastya and Time Machine
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2
2 3
2 4
4 5
Output
13
1 0
2 1
3 2
3 1
2 2
4 3
4 1
5 2
5 1
4 2
2 3
2 0
1 1
----------------------------------------------------------------------------------------------------
E. Nastya and Bees
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
1 2
2 3
3 4
4 5
5 1
4
5
Output
1 1 2
1 5 3
Input
8 9
1 2
2 3
3 4
4 5
5 1
5 6
6 7
7 8
8 4
1
5
Output
7 3 3
6 2 2
5 3 1
----------------------------------------------------------------------------------------------------
F. Nastya and CBS
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
1 -1
1
2 1 2
Output
Yes
Input
2 2
1 -2
1
2 1 2
Output
No
Input
6 2
1 2 -2 -1 1 -1
3
2 1 6
2 1 4
2 2 5
Output
Yes
Yes
No
Input
2 2
-1 1
4
2 1 2
1 1 1
1 2 -1
2 1 2
Output
No
Yes
----------------------------------------------------------------------------------------------------
