#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100100;
int i,j,k,n,m,ch,ff,nls,ans;
int A[N],B[N],a[N],b[N],Ls[N],f[N],z[N];
void R(int &x) {
	ff=x=0;
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
int getf(int x) {
	if (f[x]==x) return x;
	return f[x]=getf(f[x]);
}
int find(int x) {
	int l=1,r=nls,mid;
	while (l<r) {
		mid=(l+r)>>1;
		if (Ls[mid]==x) return mid;
		if (Ls[mid]<x) l=mid+1;
		else r=mid-1;
	}
	return l;
}
int main() {
	R(n);n++;
	for (i=1;i<n;i++) {
		R(A[i]);
		a[i]=A[i];
		A[n]^=A[i];
	}
	a[n]=A[n];
	for (i=1;i<n;i++) {
		R(B[i]);
		b[i]=B[i];
		B[n]^=B[i];
	}
	b[n]=B[n];
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	for (i=1;i<=n;i++) if (a[i]!=b[i]) return puts("-1"),0;
	a[n+1]=-1;
	for (i=1;i<=n;i++) if (a[i]!=a[i+1]) Ls[++nls]=a[i];
	for (i=1;i<=n;i++) A[i]=find(A[i]),B[i]=find(B[i]);
	for (i=1;i<=nls;i++) f[i]=i;
	for (i=1;i<n;i++) if (A[n]==B[i]) ans=-1;
	ans+=n-1;
	for (i=1;i<n;i++) {
		if (A[i]!=B[i]) {
			z[A[i]]=z[B[i]]=1;
			if (getf(A[i])!=getf(B[i])) f[f[A[i]]]=f[B[i]];
		}
		else ans--;
	} 
	for (i=1;i<=nls;i++) if (getf(i)==i && z[i]) ans++;
	printf("%d\n",max(0,ans));
}
### Prompt

Generate a CPP solution to the following problem:

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.

Examples

Input

3
0 1 2
3 1 0


Output

2


Input

3
0 1 2
0 1 2


Output

0


Input

2
1 1
0 0


Output

-1


Input

4
0 1 2 3
1 0 3 2


Output

5

### Response

```cpp
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100100;
int i,j,k,n,m,ch,ff,nls,ans;
int A[N],B[N],a[N],b[N],Ls[N],f[N],z[N];
void R(int &x) {
	ff=x=0;
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
int getf(int x) {
	if (f[x]==x) return x;
	return f[x]=getf(f[x]);
}
int find(int x) {
	int l=1,r=nls,mid;
	while (l<r) {
		mid=(l+r)>>1;
		if (Ls[mid]==x) return mid;
		if (Ls[mid]<x) l=mid+1;
		else r=mid-1;
	}
	return l;
}
int main() {
	R(n);n++;
	for (i=1;i<n;i++) {
		R(A[i]);
		a[i]=A[i];
		A[n]^=A[i];
	}
	a[n]=A[n];
	for (i=1;i<n;i++) {
		R(B[i]);
		b[i]=B[i];
		B[n]^=B[i];
	}
	b[n]=B[n];
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	for (i=1;i<=n;i++) if (a[i]!=b[i]) return puts("-1"),0;
	a[n+1]=-1;
	for (i=1;i<=n;i++) if (a[i]!=a[i+1]) Ls[++nls]=a[i];
	for (i=1;i<=n;i++) A[i]=find(A[i]),B[i]=find(B[i]);
	for (i=1;i<=nls;i++) f[i]=i;
	for (i=1;i<n;i++) if (A[n]==B[i]) ans=-1;
	ans+=n-1;
	for (i=1;i<n;i++) {
		if (A[i]!=B[i]) {
			z[A[i]]=z[B[i]]=1;
			if (getf(A[i])!=getf(B[i])) f[f[A[i]]]=f[B[i]];
		}
		else ans--;
	} 
	for (i=1;i<=nls;i++) if (getf(i)==i && z[i]) ans++;
	printf("%d\n",max(0,ans));
}
```