#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define fr(i,x,y) for(int i=x;i<=y;++i)
#define LL long long
using namespace std;
const int N=1e6+10;
map<int,int>qx;
int n,a[N],b[N],c[N],f[N],vis[N];

int find(int k){
	return f[k]==k?k:f[k]=find(f[k]);
}

void add(int x,int y){
	int xx=find(x),yy=find(y);
	if(xx!=yy){
		f[xx]=yy;vis[yy]=1;
	}
}

void fail(){
	printf("-1\n");
	exit(0);
}

int main(){
	scanf("%d",&n);
	fr(i,1,n) {
		scanf("%d",&a[i]);qx[a[i]]++;
		a[n+1]^=a[i];
	}
	qx[a[n+1]]++;
	fr(i,1,n) {
		scanf("%d",&b[i]);qx[b[i]]--;
		if(qx[b[i]]<0) fail();
		b[n+1]^=b[i];
	}
	++n;
	fr(i,1,n) c[i]=a[i];
	int ans=0;
	sort(c+1,c+1+n);
	int len=unique(c+1,c+1+n)-c-1;
	fr(i,1,n) a[i]=lower_bound(c+1,c+1+len,a[i])-c;
	fr(i,1,n) b[i]=lower_bound(c+1,c+1+len,b[i])-c;
	fr(i,1,n) f[i]=i;
	fr(i,1,n) {
		if(a[i]!=b[i]) {
			add(a[i],b[i]);
			if(i!=n) ans++;
		}
	}
	if(!ans) return printf("0\n"),0;
	vis[a[n]]=vis[b[n]]=1;
	fr(i,1,n) if(f[i]==i&&vis[i]) ans++;
	ans--;
	printf("%d\n",ans);
	return 0;
}
/*
4
0 1 2 3
1 0 3 2
*/
### Prompt

Your challenge is to write 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
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define fr(i,x,y) for(int i=x;i<=y;++i)
#define LL long long
using namespace std;
const int N=1e6+10;
map<int,int>qx;
int n,a[N],b[N],c[N],f[N],vis[N];

int find(int k){
	return f[k]==k?k:f[k]=find(f[k]);
}

void add(int x,int y){
	int xx=find(x),yy=find(y);
	if(xx!=yy){
		f[xx]=yy;vis[yy]=1;
	}
}

void fail(){
	printf("-1\n");
	exit(0);
}

int main(){
	scanf("%d",&n);
	fr(i,1,n) {
		scanf("%d",&a[i]);qx[a[i]]++;
		a[n+1]^=a[i];
	}
	qx[a[n+1]]++;
	fr(i,1,n) {
		scanf("%d",&b[i]);qx[b[i]]--;
		if(qx[b[i]]<0) fail();
		b[n+1]^=b[i];
	}
	++n;
	fr(i,1,n) c[i]=a[i];
	int ans=0;
	sort(c+1,c+1+n);
	int len=unique(c+1,c+1+n)-c-1;
	fr(i,1,n) a[i]=lower_bound(c+1,c+1+len,a[i])-c;
	fr(i,1,n) b[i]=lower_bound(c+1,c+1+len,b[i])-c;
	fr(i,1,n) f[i]=i;
	fr(i,1,n) {
		if(a[i]!=b[i]) {
			add(a[i],b[i]);
			if(i!=n) ans++;
		}
	}
	if(!ans) return printf("0\n"),0;
	vis[a[n]]=vis[b[n]]=1;
	fr(i,1,n) if(f[i]==i&&vis[i]) ans++;
	ans--;
	printf("%d\n",ans);
	return 0;
}
/*
4
0 1 2 3
1 0 3 2
*/
```