Codeforces Round 521 (Div. 3)


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

Examples
Input
6
5 2 3
100 1 4
1 10 5
1000000000 1 6
1 1 1000000000
1 1 999999999
Output
8
198
-17
2999999997
0
1
----------------------------------------------------------------------------------------------------
B. Disturbed People
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
1 1 0 1 1 0 1 0 1 0
Output
2
Input
5
1 1 0 0 0
Output
0
Input
4
1 1 1 1
Output
0
----------------------------------------------------------------------------------------------------
C. Good Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 5 1 2 2
Output
3
4 1 5
Input
4
8 3 5 2
Output
2
1 4 
Input
5
2 1 2 4 3
Output
0
----------------------------------------------------------------------------------------------------
D. Cutting Out
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 3
1 2 3 2 4 3 1
Output
1 2 3 
Input
10 4
1 3 1 3 10 3 7 7 12 3
Output
7 3 1 3
Input
15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1
Output
1 1 
----------------------------------------------------------------------------------------------------
E. Thematic Contests
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
18
2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10
Output
14
Input
10
6 6 6 3 6 1000000000 3 3 6 6
Output
9
Input
3
1337 1337 1337
Output
3
----------------------------------------------------------------------------------------------------
F1. Pictures with Kittens (easy version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 2 3
5 1 3 10 1
Output
18
Input
6 1 5
10 30 30 70 10 10
Output
-1
Input
4 3 1
1 100 1 1
Output
100
----------------------------------------------------------------------------------------------------
F2. Pictures with Kittens (hard version)
time limit per test: 2.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 2 3
5 1 3 10 1
Output
18
Input
6 1 5
10 30 30 70 10 10
Output
-1
Input
4 3 1
1 100 1 1
Output
100
----------------------------------------------------------------------------------------------------
