Codeforces Round 816 (Div. 2)


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

Examples
Input
7
7 5
5 7
1 1
100000 100000
57 228
1 5
5 1
Output
15
15
0
299998
340
5
5
----------------------------------------------------------------------------------------------------
B. Beautiful Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
1 6 3 100
3 6 3 12
3 6 3 19
5 4 7 38
5 4 7 80
99978 1000000000 100000000 1000000000000000000
1 1 0 0
4 1000000000 1000000000 1000000000000000000
Output
-1
-1
0 0 19
0 3 3 3 29
-1
-1
0
0 0 0 1000000000000000000
----------------------------------------------------------------------------------------------------
C. Monoblock
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
1 2 3 4 5
3 2
4 2
3 1
2 1
2 2
Output
29
23
35
25
35
----------------------------------------------------------------------------------------------------
D. 2+ doors
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
1 2 3
1 3 2
4 1 2
Output
0 3 2 2 
Input
1 0
Output
0 
Input
2 1
1 1 1073741823
Output
1073741823 0 
----------------------------------------------------------------------------------------------------
E. Long Way Home
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1 2
1 3 1
Output
0 1 1 
Input
4 3 1
1 2 3
2 4 5
3 4 7
Output
0 1 4 6 
Input
2 1 1
2 1 893746473
Output
0 1 
Input
5 5 2
2 1 33
1 5 93
5 3 48
2 3 21
4 2 1
Output
0 1 2 2 3 
----------------------------------------------------------------------------------------------------
F. Crop Squares
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
0.5
0.5
Output
? 4
0 0
2 0
2 3
0 3
? 4
0 0
0 1
3 1
3 0
! 1.5 0.5
----------------------------------------------------------------------------------------------------
