Codeforces Round 440 (Div. 1, based on Technocup 2018 Elimination Round 2)


A. Maximum splitting
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
12
Output
3
Input
2
6
8
Output
1
2
Input
3
1
2
3
Output
-1
-1
-1
----------------------------------------------------------------------------------------------------
B. Something with XOR Queries
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
0
0
3
2
3
2
Output
? 0 0
? 1 1
? 1 2
? 0 2
? 2 1
? 2 0
!
1
0 1 2
Input
4
2
3
2
0
2
3
2
0
Output
? 0 1
? 1 2
? 2 3
? 3 3
? 3 2
? 2 1
? 1 0
? 0 0
!
2
3 1 2 0
----------------------------------------------------------------------------------------------------
C. Points, Lines and Ready-made Titles
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1
1 2
2 1
2 2
Output
16
Input
2
-1 -1
0 1
Output
9
----------------------------------------------------------------------------------------------------
D. Paths
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
Output
8
Input
10
Output
44
----------------------------------------------------------------------------------------------------
E. Restore the Tree
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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