## An XOR Problem

View as PDF

Points: 20
Time limit: 3.0s
Memory limit: 128M

Problem types

You are given an array $$a$$ of length $$N$$. You repeatedly perform the following operation:

• Let the XOR of all elements in $$a$$ be $$x$$. Select an integer $$i\ (1 \le i \le N)$$ and replace $$a_i$$ with $$x$$.

Your goal is to match $$a$$ with another array $$b$$. Determine if it is possible to achieve the goal, and the minimum number of operations required.

#### Input Specification

The first line will contain the $$N\ (1 \le N \le 10^5)$$.

The second line will contain $$N$$ integers, $$a_i\ (0 \le a_i < 2^{30})$$, the original array.

The third line will contain $$N$$ integers, $$b_i\ (0 \le b_i < 2^{30})$$, the array you wish to achieve.

#### Output Specification

Output the minimum number of operations required. If it is impossible, output -1.

#### Sample Input 1

3
0 1 2
3 1 0

#### Sample Output 1

2

#### Sample Input 2

3
0 1 2
0 1 2

#### Sample Output 2

0

#### Sample Input 3

2
1 1
0 0

#### Sample Output 3

-1

#### Sample Input 4

4
0 1 2 3
1 0 3 2

#### Sample Output 4

5