Codeforces Round 509 (Div. 2)


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

Examples
Input
4
10 13 12 8
Output
2
Input
5
7 5 6 4 8
Output
0
----------------------------------------------------------------------------------------------------
B. Buying a TV Set
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
----------------------------------------------------------------------------------------------------
C. Coffee Break
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5 3
3 5 1 2
Output
3
3 1 1 2 
Input
10 10 1
10 5 7 4 6 3 2 1 9 8
Output
2
2 1 1 2 2 1 2 1 1 2 
----------------------------------------------------------------------------------------------------
D. Glider
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
2 5
7 9
10 11
Output
10
Input
5 10
5 7
11 12
16 20
25 26
30 33
Output
18
Input
1 1000000000
1 1000000000
Output
1999999999
----------------------------------------------------------------------------------------------------
E. Tree Reconstruction
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 4
1 4
3 4
Output
YES
1 3
3 2
2 4
Input
3
1 3
1 3
Output
NO
Input
3
1 2
2 3
Output
NO
----------------------------------------------------------------------------------------------------
F. Ray in the tube
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
1 5 6
1 3
3
Output
3
----------------------------------------------------------------------------------------------------
