#AGC016D. [AGC016D] XOR Replace

[AGC016D] XOR Replace

Score : 10001000 points

Problem Statement

There is a sequence of length NN: a=(a1,a2,...,aN)a = (a_1, a_2, ..., a_N). Here, each aia_i is a non-negative integer.

Snuke can repeatedly perform the following operation:

  • Let the XOR of all the elements in aa be xx. Select an integer ii (1iN1 \leq i \leq N) and replace aia_i with xx.

Snuke's objective is to match aa with another sequence b=(b1,b2,...,bN)b = (b_1, b_2, ..., b_N). Here, each bib_i is a non-negative integer.

Determine whether the objective is achievable, and find the minimum necessary number of operations if the answer is positive.

Constraints

  • 2N1052 \leq N \leq 10^5
  • aia_i and bib_i are integers.
  • 0ai,bi<2300 \leq a_i, b_i < 2^{30}

Input

Input is given from Standard Input in the following format:

NN

a1a_1 a2a_2 ...... aNa_N

b1b_1 b2b_2 ...... bNb_N

Output

If the objective is achievable, print the minimum necessary number of operations. Otherwise, print -1 instead.

3
0 1 2
3 1 0
2

At first, the XOR of all the elements of aa is 33. If we replace a1a_1 with 33, aa becomes (3,1,2)(3, 1, 2).

Now, the XOR of all the elements of aa is 00. If we replace a3a_3 with 00, aa becomes (3,1,0)(3, 1, 0), which matches bb.

3
0 1 2
0 1 2
0
2
1 1
0 0
-1
4
0 1 2 3
1 0 3 2
5