Codeforces Round 489 (Div. 2)


A. Nastya and an Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 1 1 1 1
Output
1
Input
3
2 0 -1
Output
2
Input
4
5 -6 -5 1
Output
4
----------------------------------------------------------------------------------------------------
B. Nastya Studies Informatics
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 2 1 2
Output
2
Input
1 12 1 12
Output
4
Input
50 100 3 30
Output
0
----------------------------------------------------------------------------------------------------
C. Nastya and a Wardrobe
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 0
Output
4
Input
2 1
Output
7
Input
3 2
Output
21
----------------------------------------------------------------------------------------------------
D. Nastya and a Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1
1
Output
1
Input
4 2
6 3 8 1
Output
2
----------------------------------------------------------------------------------------------------
E. Nastya and King-Shamans
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
1 3
1 2
Output
-1
Input
3 4
2 2 3
1 1
1 2
2 4
3 6
Output
3
2
-1
3
Input
10 7
0 3 1 4 6 2 7 8 10 1
2 5
1 3
9 36
4 10
4 9
1 2
1 0
Output
1
-1
9
-1
4
-1
1
----------------------------------------------------------------------------------------------------
