CPC '21 Contest 1 P2 - AQT and Multiset

View as PDF

Submit solution


Points: 7 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

AQT has two multisets of integers A and B, both of size 2N+1 for some non-negative integer N. Help AQT determine the smallest non-negative integer c such that after XOR-ing each element in A by c, the multisets A and B are equal.

Constraints

In all subtasks,

0 \le A_i, B_i < 2^{63}

0 \le N \le 2 \cdot 10^5

Subtask 1 [5%]

0 \le A_i, B_i < 2^{15}

0 \le N \le 100

Subtask 2 [15%]

0 \le N \le 10^3

Subtask 3 [80%]

No additional constraints.

Input Specification

The first line contains one integer N.

The second line contains 2N+1 space separated integers, A_1, \dots, A_{2N+1}.

The third line contains 2N+1 space separated integers, B_1, \dots, B_{2N+1}.

Output Specification

Output the smallest possible value of c as described above on a single line. If no such value exists, output -1 on a single line.

Sample Input 1

3
84 80 88 84 93 84 86
5 1 12 7 9 5 5

Sample Output 1

81

Explanation of Sample Output 1

The smallest possible solution is c = 81. If we XOR each element in A by 81, we have A = \{5, 1, 9, 5, 12, 5, 7\}, which is equivalent to B.

Sample Input 2

1
3 1 9
1 12 123

Sample Output 2

-1

Comments

There are no comments at the moment.