Codeforces Round 899 (Div. 2)


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

Examples
Input
3
5
1 3 2 6 7
4
2 3 4 5
1
1
Output
8
4
2
----------------------------------------------------------------------------------------------------
B. Sets and Union
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
3 1 2 3
2 4 5
2 3 4
4
4 1 2 3 4
3 2 5 6
3 3 5 6
3 4 5 6
5
1 1
3 3 6 10
1 9
2 1 3
3 5 8 9
1
2 4 28
Output
4
5
6
0
----------------------------------------------------------------------------------------------------
C. Card Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4
-4 1 -3 5
4
1 -2 3 -4
3
-1 3 -5
1
-1
Output
5
4
2
0
----------------------------------------------------------------------------------------------------
D. Tree XOR
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2
4
3 2 1 0
1 2
2 3
2 4
1
100
Output
8 6 12 10 
0 
----------------------------------------------------------------------------------------------------
E1. Two Permutations (Easy Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5
2 1 3
5 2 1 4 3
Output
2
3 4
2 4
Input
4 4
3 4 2 1
2 4 1 3
Output
5
4 2
3 3
1 4
3 2
4 1
Input
2 2
1 2
2 1
Output
-1
----------------------------------------------------------------------------------------------------
E2. Two Permutations (Hard Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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