Good Bye 2015


A. New Year and Days
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 of week
Output
52
Input
30 of month
Output
11
----------------------------------------------------------------------------------------------------
B. New Year and Old Property
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 10
Output
2
Input
2015 2015
Output
1
Input
100 105
Output
0
Input
72057594000000000 72057595000000000
Output
26
----------------------------------------------------------------------------------------------------
C. New Year and Domino
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 8
....#..#
.#......
##.#....
##..#.##
........
4
1 1 2 3
4 1 4 1
1 2 4 5
2 5 5 8
Output
4
0
10
15
Input
7 39
.......................................
.###..###..#..###.....###..###..#..###.
...#..#.#..#..#.........#..#.#..#..#...
.###..#.#..#..###.....###..#.#..#..###.
.#....#.#..#....#.....#....#.#..#..#.#.
.###..###..#..###.....###..###..#..###.
.......................................
6
1 1 3 20
2 10 6 30
2 10 7 30
2 2 7 7
1 7 7 7
1 8 7 8
Output
53
89
120
23
0
2
----------------------------------------------------------------------------------------------------
D. New Year and Ancient Prophecy
time limit per test: 2.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
123434
Output
8
Input
8
20152016
Output
4
----------------------------------------------------------------------------------------------------
E. New Year and Three Musketeers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
10 20 30
1 1 1 1 50
Output
2
Input
5
10 20 30
1 1 1 1 51
Output
3
Input
7
30 20 10
34 19 50 33 88 15 20
Output
-1
Input
6
10 5 10
10 9 5 25 20 5
Output
3
----------------------------------------------------------------------------------------------------
F. New Year and Cleaning
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 10 2
R
Output
30
Input
3 4 6
RUL
Output
134
Input
4 1 500000
RLRL
Output
-1
----------------------------------------------------------------------------------------------------
G. New Year and Cake
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 4
2 7
5 7
5 4
3 -2
Output
90
Input
4
-1000000000 -5000000
0 1234567
1 1
-5 -100000000
Output
525185196
Input
8
-10 0
-6 6
0 10
6 6
10 0
6 -6
0 -10
-6 -6
Output
5216
----------------------------------------------------------------------------------------------------
H. New Year and Forgotten Tree
time limit per test: 7 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
12
? ?
? ?
? ?
? ??
?? ?
?? ??
? ??
? ?
? ?
? ?
? ?
Output
3 1
1 6
9 1
2 10
1 7
8 1
1 4
1 10
5 1
10 11
12 1
Input
12
?? ??
? ?
? ?
? ??
?? ?
?? ??
? ??
? ?
? ?
?? ??
? ?
Output
-1
----------------------------------------------------------------------------------------------------
