Codeforces Round 536 (Div. 2)


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

Examples
Input
5
.....
.XXX.
.XXX.
.XXX.
.....
Output
1
Input
2
XX
XX
Output
0
Input
6
......
X.X.X.
.X.X.X
X.X.X.
.X.X.X
......
Output
4
----------------------------------------------------------------------------------------------------
B. Lunar New Year and Food Ordering
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 5
8 6 2 1 4 5 7 5
6 3 3 2 6 2 3 2
2 8
1 4
4 7
3 4
6 10
Output
22
24
14
10
39
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66
Output
36
396
3996
39996
399996
0
Input
6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6
Output
36
11058
99996
4333326
0
0
----------------------------------------------------------------------------------------------------
C. Lunar New Year and Number Division
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
8 5 2 3
Output
164
Input
6
1 1 1 2 2 2
Output
27
----------------------------------------------------------------------------------------------------
D. Lunar New Year and a Wander
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 2
1 3
Output
1 2 3 
Input
5 5
1 4
3 4
5 4
3 2
1 5
Output
1 4 3 2 5 
Input
10 10
1 4
6 8
2 5
3 7
9 4
5 6
3 4
8 10
8 9
1 10
Output
1 4 3 7 9 8 6 5 2 10 
----------------------------------------------------------------------------------------------------
E. Lunar New Year and Red Envelopes
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 0 2
1 3 4 5
2 5 5 8
Output
13
Input
10 1 6
1 1 2 4
2 2 6 2
3 3 3 3
4 4 4 5
5 5 5 7
6 6 6 9
Output
2
Input
12 2 6
1 5 5 4
4 6 6 2
3 8 8 3
2 9 9 5
6 10 10 7
8 12 12 9
Output
11
----------------------------------------------------------------------------------------------------
F. Lunar New Year and a Recursive Sequence
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3 5
4 16
Output
4
Input
5
4 7 1 5 6
7 14187219
Output
6
Input
8
2 3 5 6 1 7 9 10
23333 1
Output
1
Input
1
2
88888 66666
Output
-1
Input
3
998244352 998244352 998244352
4 2
Output
-1
Input
10
283 463 213 777 346 201 463 283 102 999
2333333 6263423
Output
382480067
----------------------------------------------------------------------------------------------------
