Codeforces Round 829 (Div. 1)


A1. Make Nonzero Sum (easy version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4
1 1 1 1
6
-1 1 1 1 1 1
3
1 -1 1
1
1
Output
1
1 4
2
1 3
4 6
-1
-1
----------------------------------------------------------------------------------------------------
A2. Make Nonzero Sum (hard version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4
0 0 0 0
7
-1 1 0 1 0 1 0
5
0 -1 1 0 1
3
1 0 1
1
1
Output
4
1 1
2 2
3 3
4 4
4
1 1
2 2
3 5
6 7
-1
2
1 1
2 3
-1
----------------------------------------------------------------------------------------------------
B. Factorial Divisibility
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 4
3 2 2 2 3 3
Output
Yes
Input
8 3
3 2 2 2 2 2 1 1
Output
Yes
Input
7 8
7 7 7 7 7 7 7
Output
No
Input
10 5
4 3 2 1 4 3 2 4 3 4
Output
No
Input
2 500000
499999 499999
Output
No
----------------------------------------------------------------------------------------------------
C. Wish I Knew How to Sort
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3
0 1 0
5
0 0 1 1 1
6
1 1 1 0 0 1
Output
3
0
249561107
----------------------------------------------------------------------------------------------------
D. The Beach
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 5
5 2
.LR##
##LR.
Output
4
Input
2 3
4 5
LR.
#.#
Output
-1
Input
4 3
10 10
.LR
###
UU#
DD.
Output
-1
Input
3 6
10 7
.U##.#
#DLR##
.##LR.
Output
24
----------------------------------------------------------------------------------------------------
E. N Machines
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2 1 3
* 2
+ 1
+ 1
Output
6
Input
4 2 2 2
* 2
+ 1
* 3
+ 2
Output
21
Input
8 2 1 1
* 2
+ 1
* 4
+ 1
+ 1
+ 1
* 5
+ 3
Output
240
----------------------------------------------------------------------------------------------------
F. Minecraft Series
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 2 1 2
1 1 2
Output
0
Input
2 2 2 2
1 1 1
2 2 2
Output
2
Input
2 2 4 2
1 1 1
1 1 -1
1 2 1
2 2 1
Output
4
----------------------------------------------------------------------------------------------------
