Codeforces Round 139 (Div. 2)


A. Dice Tower
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
6
3 2
5 4
2 4
Output
YES
Input
3
3
2 6
4 1
5 3
Output
NO
----------------------------------------------------------------------------------------------------
B. Well-known Numbers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 2
Output
3
0 2 3
Input
21 5
Output
3
4 1 16
----------------------------------------------------------------------------------------------------
C. Barcode
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 5 1 2
##.#.
.###.
###..
#...#
.##.#
###..
Output
11
Input
2 5 1 1
#####
.....
Output
5
----------------------------------------------------------------------------------------------------
D. Snake
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5
##...
..1#@
432#.
...#.
Output
4
Input
4 4
#78#
.612
.543
..@.
Output
6
Input
3 2
3@
2#
1#
Output
-1
----------------------------------------------------------------------------------------------------
E. Unsolvable
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
Output
1
Input
2
Output
3
Input
3
Output
15
----------------------------------------------------------------------------------------------------
