Codeforces Round 775 (Div. 2, based on Moscow Open Olympiad in Informatics)


A. Game
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
1 1
5
1 0 1 0 1
4
1 0 1 1
Output
0
4
2
----------------------------------------------------------------------------------------------------
B. Game of Ball Passing
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
2 3
1 2 3
3 2 1
Output
7
Input
3 4
1 1 2 2
2 1 1 2
2 2 1 1
Output
76
Input
4 4
1 1 2 3
2 1 1 2
3 1 2 1
1 1 2 1
Output
129
----------------------------------------------------------------------------------------------------
D. Integral Array
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
3 5
1 2 5
4 10
1 3 3 7
1 2
2
1 1
1
Output
Yes
No
No
Yes
Input
1
1 1000000
1000000
Output
No
----------------------------------------------------------------------------------------------------
E. Tyler and Strings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
1 2 2
2 1 2 1
Output
2
Input
4 4
1 2 3 4
4 3 2 1
Output
23
Input
4 3
1 1 1 2
1 1 2
Output
1
----------------------------------------------------------------------------------------------------
F. Serious Business
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 3
1 0 2 -1
-3 1 9 2
3 2 4 1
1 2 5
2 3 4
1 4 14
Output
13
Input
5 4
-20 -10 -11 -10 1
1 3 3 6 3
14 -20 3 6 2
1 5 13
1 2 2
3 5 3
2 3 1
Output
-4
----------------------------------------------------------------------------------------------------
