#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,a[200010],b[200010],na[200010],nb[200010],f[200010];
int find(int x){return ((f[x]<0)?x:f[x]=find(f[x]));}
int main(){
	n=read();int i,xa=0,xb=0,ans=0,cnt,t1,t2;
	for(i=1;i<=n;i++) xa^=(na[i]=a[i]=read());
	for(i=1;i<=n;i++) xb^=(nb[i]=b[i]=read());
	n++;
	na[n]=a[n]=xa;nb[n]=b[n]=xb;
	sort(na+1,na+n+1);sort(nb+1,nb+n+1);
	for(i=1;i<=n;i++) if(na[i]!=nb[i]){puts("-1");return 0;}
	for(i=1;i<n;i++) ans+=(a[i]!=b[i]);
	if(!ans){puts("0");return 0;}
	cnt=unique(na+1,na+1+n)-na-1;
	memset(f,-1,sizeof(f));
//	cout<<"final cnt "<<cnt<<'\n';
//	for(i=1;i<=cnt;i++) cout<<i<<' '<<a[i]<<'\n';
	for(i=1;i<=n;i++){
		a[i]=lower_bound(na+1,na+cnt+1,a[i])-na;
		b[i]=lower_bound(na+1,na+cnt+1,b[i])-na;
//		cout<<"get "<<a[i]<<' '<<b[i]<<'\n';
		t1=find(a[i]);t2=find(b[i]);
		if(t1!=t2) f[t1]+=f[t2],f[t2]=t1;
	}
	if(a[n]==b[n]&&f[find(a[n])]==-1) ans++;
	for(i=1;i<=n;i++) ans+=(f[i]<-1);
	printf("%d\n",ans-1);
}


















### Prompt

Construct a cpp code solution to the problem outlined:

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<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cassert>
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,a[200010],b[200010],na[200010],nb[200010],f[200010];
int find(int x){return ((f[x]<0)?x:f[x]=find(f[x]));}
int main(){
	n=read();int i,xa=0,xb=0,ans=0,cnt,t1,t2;
	for(i=1;i<=n;i++) xa^=(na[i]=a[i]=read());
	for(i=1;i<=n;i++) xb^=(nb[i]=b[i]=read());
	n++;
	na[n]=a[n]=xa;nb[n]=b[n]=xb;
	sort(na+1,na+n+1);sort(nb+1,nb+n+1);
	for(i=1;i<=n;i++) if(na[i]!=nb[i]){puts("-1");return 0;}
	for(i=1;i<n;i++) ans+=(a[i]!=b[i]);
	if(!ans){puts("0");return 0;}
	cnt=unique(na+1,na+1+n)-na-1;
	memset(f,-1,sizeof(f));
//	cout<<"final cnt "<<cnt<<'\n';
//	for(i=1;i<=cnt;i++) cout<<i<<' '<<a[i]<<'\n';
	for(i=1;i<=n;i++){
		a[i]=lower_bound(na+1,na+cnt+1,a[i])-na;
		b[i]=lower_bound(na+1,na+cnt+1,b[i])-na;
//		cout<<"get "<<a[i]<<' '<<b[i]<<'\n';
		t1=find(a[i]);t2=find(b[i]);
		if(t1!=t2) f[t1]+=f[t2],f[t2]=t1;
	}
	if(a[n]==b[n]&&f[find(a[n])]==-1) ans++;
	for(i=1;i<=n;i++) ans+=(f[i]<-1);
	printf("%d\n",ans-1);
}


















```