Codeforces Round 864 (Div. 2)


A. Li Hua and Maze
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4 4
2 2 3 3
6 7
1 1 2 3
9 9
5 1 3 6
Output
4
2
3
----------------------------------------------------------------------------------------------------
B. Li Hua and Pattern
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4 0
1 1 1 1
0 0 0 1
1 0 1 0
1 1 1 1
4 3
1 0 1 1
1 0 0 0
0 1 0 1
1 1 0 1
5 4
0 0 0 0 0
0 1 1 1 1
0 1 0 0 0
1 1 1 1 1
0 0 0 0 0
Output
NO
YES
YES
----------------------------------------------------------------------------------------------------
C. Li Hua and Chess
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
3 4
1
2
5 3
3
1
2
Output
? 2 3
? 2 4
! 2 2
? 2 2
? 5 2
? 5 3
! 5 1
----------------------------------------------------------------------------------------------------
D. Li Hua and Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 4
1 1 1 1 1 1 1
1 2
1 3
2 4
2 5
3 6
6 7
1 6
2 3
1 6
1 2
Output
2
3
3
Input
10 14
-160016413 -90133231 -671446275 -314847579 -910548234 121155052 -359359950 83112406 -704889624 145489303
1 6
1 10
10 8
1 4
3 4
2 7
2 5
3 2
9 8
1 4
2 2
2 4
1 4
1 10
2 10
1 9
1 6
2 8
2 10
1 5
1 8
1 1
2 5
Output
-2346335269
-314847579
-476287915
-704889624
121155052
-1360041415
228601709
-2861484545
----------------------------------------------------------------------------------------------------
E. Li Hua and Array
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 4
8 1 6 3 7
2 1 5
2 3 4
1 1 3
2 3 4
Output
10
2
1
----------------------------------------------------------------------------------------------------
F. Li Hua and Path
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
2 1
1 3
1 4
4 6
4 7
6 5
2
5
6
Output
11
15
19
----------------------------------------------------------------------------------------------------
