Educational Codeforces Round 138 (Rated for Div. 2)


A. Cowardly Rooks
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 2
1 2
2 1
3 1
2 2
Output
NO
YES
----------------------------------------------------------------------------------------------------
B. Death's Blessing
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
10
0
3
100 1 100
1 100 1
4
2 6 7 3
3 6 0 5
2
1000000000 1000000000
1000000000 1000000000
Output
10
203
26
3000000000
----------------------------------------------------------------------------------------------------
C. Number Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 1 2
4
4 4 4 4
1
1
5
1 3 2 1 1
Output
2
0
1
3
----------------------------------------------------------------------------------------------------
D. Counting Arrays
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 3
Output
6
Input
4 2
Output
26
Input
4 6
Output
1494
Input
1337 424242424242
Output
119112628
----------------------------------------------------------------------------------------------------
E. Cactus Wall
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 4
.#..
..#.
3 3
#.#
...
.#.
5 5
.....
.....
.....
.....
.....
4 3
#..
.#.
#.#
...
Output
YES
.#.#
#.#.
NO
YES
....#
...#.
..#..
.#...
#....
YES
#..
.#.
#.#
...
----------------------------------------------------------------------------------------------------
F. Distance to the Path
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
1 2
1 3
4 2
5 2
3 6
14
2 4 5 10 2
1 3
1 6
2 1 1 10 20
2 6 6 10 20
1 3
2 3 2 10 0
2 5 2 10 1
1 1
1 2
1 3
1 4
1 5
1 6
Output
10
0
30
50
50
40
40
40
20
----------------------------------------------------------------------------------------------------
