#agc016d. [agc016_d]XOR Replace
[agc016_d]XOR Replace
Problem Statement
There is a sequence of length : . Here, each is a non-negative integer.
Snuke can repeatedly perform the following operation:
- Let the XOR of all the elements in be . Select an integer () and replace with .
Snuke's objective is to match with another sequence . Here, each 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
- and are integers.
Input
Input is given from Standard Input in the following format:
Output
If the objective is achievable, print the minimum necessary number of operations. Otherwise, print -1
instead.
Sample Input 1
3
0 1 2
3 1 0
Sample Output 1
2
At first, the XOR of all the elements of is . If we replace with , becomes .
Now, the XOR of all the elements of is . If we replace with , becomes , which matches .
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