Educational Codeforces Round 117 (Rated for Div. 2)


A. Distance
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
10
49 3
2 50
13 0
0 41
42 0
0 36
13 37
42 16
42 13
0 0
Output
23 3
1 25
-1 -1
-1 -1
21 0
0 18
13 12
25 4
-1 -1
0 0
----------------------------------------------------------------------------------------------------
B. Special Permutation
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7
6 2 5
6 1 3
6 4 3
4 2 4
10 5 3
2 1 2
2 2 1
Output
4 2 6 5 3 1
-1
6 4 5 1 3 2 
3 2 4 1 
-1
1 2 
2 1 
----------------------------------------------------------------------------------------------------
C. Chat Ban
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7
4 6
4 7
1 2
3 7
2 5
100 1
1000000000 923456789987654321
Output
3
4
1
4
3
1
1608737403
----------------------------------------------------------------------------------------------------
D. X-Magic Pair
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
8
6 9 3
15 38 7
18 8 8
30 30 30
40 50 90
24 28 20
365 216 52
537037812705867558 338887693834423551 3199921013340
Output
YES
YES
YES
YES
NO
YES
YES
YES
----------------------------------------------------------------------------------------------------
E. Messages
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
10 1
10 2
5 2
Output
2
5 10 
Input
3
10 1
5 2
10 1
Output
1
10 
Input
4
1 1
2 2
3 3
4 4
Output
3
2 3 4 
Input
3
13 2
42 2
37 2
Output
3
42 13 37
----------------------------------------------------------------------------------------------------
F. Armor and Weapons
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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

Examples
Input
6
1 1 1 1 1 1
Output
0 720
Input
1
1000000
Output
499833345 1
Input
7
123 451 234 512 345 123 451
Output
339854850 882811119
----------------------------------------------------------------------------------------------------
