Codeforces Round 665 (Div. 2)


A. Distance and Axis
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
----------------------------------------------------------------------------------------------------
B. Ternary Sequence
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3 2
3 3 1
4 0 1
2 3 0
0 0 1
0 0 1
Output
4
2
0
----------------------------------------------------------------------------------------------------
C. Mere Array
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
8
6
4 3 6 6 2 9
4
4 5 6 7
5
7 5 2 2 4
Output
YES
YES
YES
NO
----------------------------------------------------------------------------------------------------
D. Maximum Distributed Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
1 2
2 3
3 4
2
2 2
4
3 4
1 3
3 2
2
3 2
7
6 1
2 3
4 6
7 3
5 1
3 6
4
7 5 13 3
Output
17
18
286
----------------------------------------------------------------------------------------------------
E. Divide Square
time limit per test: 2 seconds
memory limit per test: 384 megabytes
input: standard input
output: standard output

Examples
Input
3 3
2 3 1000000
4 0 4
3 0 1000000
4 0 1
2 0 5
3 1 1000000
Output
7
----------------------------------------------------------------------------------------------------
F. Reverse and Swap
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
7 4 9 9
1 2 8
3 1
4 2 4
Output
24
Input
3 8
7 0 8 8 7 1 5 2
4 3 7
2 1
3 2
4 1 6
2 3
1 5 16
4 8 8
3 0
Output
29
22
1
----------------------------------------------------------------------------------------------------
