Codeforces Round 875 (Div. 2)


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

Examples
Input
5
5
1 2 4 5 3
2
1 2
1
1
3
3 2 1
4
1 4 3 2
Output
1 2 4 3 5
2 1
1
1 2 3
1 2 3 4
----------------------------------------------------------------------------------------------------
B. Array merging
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
2
2
3
1 2 3
4 5 6
2
1 2
2 1
5
1 2 2 2 2
2 1 1 1 1
Output
2
1
2
5
----------------------------------------------------------------------------------------------------
C. Copil Copac Draws Trees
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
6
4 5
1 3
1 2
3 4
1 6
7
5 6
2 4
2 7
1 3
1 2
4 5
Output
2
3
----------------------------------------------------------------------------------------------------
D. The BOSS Can Count Pairs
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
3
2 3 2
3 3 1
8
4 2 8 2 1 2 7 5
3 5 8 8 1 1 6 5
8
4 4 8 8 8 8 8 8
8 8 8 8 8 8 8 8
Output
2
7
1
----------------------------------------------------------------------------------------------------
E. Hyperregular Bracket Strings
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
6 0
5 0
8 1
1 3
10 2
3 4
6 9
1000 3
100 701
200 801
300 901
28 5
1 12
3 20
11 14
4 9
18 19
4 3
1 4
1 4
1 4
Output
5
0
0
4
839415253
140
2
----------------------------------------------------------------------------------------------------
F. Mex Tree
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 2
2 3
4
1 2
1 3
1 4
10
1 2
1 3
3 4
3 5
1 6
5 7
2 8
6 9
6 10
1
Output
8
15
96
1
----------------------------------------------------------------------------------------------------
