Codeforces Global Round 3


A. Another One Bites The Dust
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1 1
Output
4
Input
2 1 2
Output
7
Input
3 5 2
Output
11
Input
2 2 1
Output
6
Input
1000000000 1000000000 1000000000
Output
4000000000
----------------------------------------------------------------------------------------------------
B. Born This Way
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5 1 1 2
1 3 5 7
1 2 3 9 10
Output
11
Input
2 2 4 4 2
1 10
10 20
Output
-1
Input
4 3 2 3 1
1 999999998 999999999 1000000000
3 4 1000000000
Output
1000000003
----------------------------------------------------------------------------------------------------
C. Crazy Diamond
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 1
Output
1
1 2
Input
4
3 4 1 2
Output
4
1 4
1 4
1 3
2 4
Input
6
2 5 3 1 4 6
Output
3
1 5
2 5
1 4
----------------------------------------------------------------------------------------------------
D. Dirty Deeds Done Dirt Cheap
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 7
6 4
2 10
9 8
3 5
Output
3
1 5 3
Input
3
5 4
3 2
6 1
Output
3
3 2 1
----------------------------------------------------------------------------------------------------
E. Earth Wind and Fire
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 2 7 4 9
5 4 5 5 5
Output
YES
4
4 3 1
2 3 1
2 5 2
1 5 2
Input
3
1 5 10
3 5 7
Output
NO
----------------------------------------------------------------------------------------------------
F. Foo Fighters
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
17 206
-6 117
-2 151
9 93
6 117
Output
64
Input
1
1 1
Output
1
----------------------------------------------------------------------------------------------------
G. Gold Experience
time limit per test: 2 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
6 3
6 15 10 8 14 12
Output
1 3 6
Input
8 4
11 15 10 6 21 15 10 6
Output
1 2 3 4
Input
10 5
3003 17017 3230 49742 546 41990 17765 570 21945 36465
Output
4 6 9 10 1
----------------------------------------------------------------------------------------------------
H. Holy Diver
time limit per test: 3 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
5
0 0 0 1
0 1 0 5
5 2 1 0
5 2 1 0
2 4 3 3
Output
1
1
2
6
3
Input
5
2 0 0 2
2 0 1 1
0 0 2 0
3 2 2 0
0 2 3 0
Output
0
0
3
0
0
----------------------------------------------------------------------------------------------------
