Problem:
Score : 1000 points

Problem Statement

There is a sequence of length N: a = (a_1, a_2, ..., a_N).
Here, each a_i is a non-negative integer.

Snuke can repeatedly perform the following operation:

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

Snuke's objective is to match a with another sequence b = (b_1, b_2, ..., b_N).
Here, each b_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

2 ≤ N ≤ 10^5

a_i and b_i are integers.

0 ≤ a_i, b_i < 2^{30}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N
b_1 b_2 ... b_N

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 a is 3.
If we replace a_1 with 3, a becomes (3, 1, 2).

Now, the XOR of all the elements of a is 0.
If we replace a_3 with 0, a becomes (3, 1, 0), which matches b.

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

Solution in Go (1.6) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
)

type IOTp struct {
	iBuffer []byte
	iPos int
}
func (this *IOTp) GetChar() byte {
	res:=this.iBuffer[this.iPos]
	this.iPos++
	return res
}
func (this *IOTp) ReadInt() int {
	res:=0
	k:=1
	for ch:=this.iBuffer[this.iPos]; !(ch>='0' && ch<='9'); ch=this.iBuffer[this.iPos]{
		if ch=='-' {
			k=-1
		}
		this.iPos++
	}
	for ch:=this.iBuffer[this.iPos]; ch>='0' && ch<='9'; ch=this.iBuffer[this.iPos]{
		res=res*10+int(ch-'0')
		this.iPos++
	}
	res*=k
	return res
}
func NewIOTp() *IOTp {
	now:=new(IOTp)
	//inputFile,_:=os.Open("in.txt")
	inputFile:=os.Stdin
	now.iBuffer,_=ioutil.ReadAll(inputFile)
	now.iBuffer=append(now.iBuffer, '\n')
	now.iPos=0
	return now
}
var cin *bufio.Reader
var cout *bufio.Writer
const MAXN=100000
func main() {
	IO:=NewIOTp()
	cout=bufio.NewWriter(os.Stdout)
	n:=IO.ReadInt()
	var a,b [MAXN+10]int
	for i:=1; i<=n; i++ {
		a[i]=IO.ReadInt()
	}
	for i:=1; i<=n; i++ {
		b[i]=IO.ReadInt()
	}
	for _,v:=range a[1:n+1] {
		a[n+1]^=v
	}
	for _,v:=range b[1:n+1] {
		b[n+1]^=v
	}
	m:=make(map[int]int)
	for _,v:=range a[1:n+2] {
		m[v]++
	}
	for _,v:=range b[1:n+2] {
		m[v]--
	}
	for _,v:=range m {
		if v!=0 {
			fmt.Println(-1)
			return;
		}
	}
	ans:=0
	flag:=true
	for i:=range a[1:n+2] {
		if a[i]!=b[i] {
			if b[i]==a[n+1] {
				flag=false
			}
			ans++
		}
	}
	if a[n+1]==b[n+1] && ans!=0 && flag {
		ans++
	}
	fmt.Println(ans)
	cout.Flush()
}