#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 100007
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
int i,j,k,n,x,y,gx,gy,cnt,ans;
int a[N],b[N],c[N],d[N];
int fa[N];
bool bz[N];
int get(int x){return fa[x]==x?x:fa[x]=get(fa[x]);}
int read(){
	int fh=1,res=0;char ch;
	while((ch<'0'||ch>'9')&&(ch^'0'))ch=getchar();
	if(ch=='-')fh=-1,ch=getchar();
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+(ch^'0'),ch=getchar(); 
	return fh*res;
}
int main(){
	n=read();
	fo(i,1,n)a[i]=read(),a[n+1]^=a[i];fo(i,1,n)b[i]=read(),b[n+1]^=b[i];
	memcpy(c,a,sizeof(c));memcpy(d,b,sizeof(d));n++;
	sort(c+1,c+n+1);sort(d+1,d+n+1);
	fo(i,1,n)if(c[i]!=d[i]){printf("-1");return 0;}
	cnt=unique(c+1,c+n+1)-c-1;
	fo(i,1,cnt)fa[i]=i;
	fo(i,1,n)a[i]=lower_bound(c+1,c+cnt+1,a[i])-c,b[i]=lower_bound(c+1,c+cnt+1,b[i])-c;
	fo(i,1,n){
		if(a[i]==b[i]&&i<n)continue;
		ans+=(i<n);
		x=a[i],y=b[i];
		gx=get(x);gy=get(y);
		if(gx!=gy)fa[gy]=gx;
		bz[x]=bz[y]=1;
	}
	fo(i,1,cnt)fa[i]=get(fa[i]);
	fo(i,1,cnt)if(bz[i]&&fa[i]==i)ans++;
	if(ans)ans--;
	printf("%d",ans);
	return 0;
}
### Prompt

In cpp, your task is to solve 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<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 100007
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
int i,j,k,n,x,y,gx,gy,cnt,ans;
int a[N],b[N],c[N],d[N];
int fa[N];
bool bz[N];
int get(int x){return fa[x]==x?x:fa[x]=get(fa[x]);}
int read(){
	int fh=1,res=0;char ch;
	while((ch<'0'||ch>'9')&&(ch^'0'))ch=getchar();
	if(ch=='-')fh=-1,ch=getchar();
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+(ch^'0'),ch=getchar(); 
	return fh*res;
}
int main(){
	n=read();
	fo(i,1,n)a[i]=read(),a[n+1]^=a[i];fo(i,1,n)b[i]=read(),b[n+1]^=b[i];
	memcpy(c,a,sizeof(c));memcpy(d,b,sizeof(d));n++;
	sort(c+1,c+n+1);sort(d+1,d+n+1);
	fo(i,1,n)if(c[i]!=d[i]){printf("-1");return 0;}
	cnt=unique(c+1,c+n+1)-c-1;
	fo(i,1,cnt)fa[i]=i;
	fo(i,1,n)a[i]=lower_bound(c+1,c+cnt+1,a[i])-c,b[i]=lower_bound(c+1,c+cnt+1,b[i])-c;
	fo(i,1,n){
		if(a[i]==b[i]&&i<n)continue;
		ans+=(i<n);
		x=a[i],y=b[i];
		gx=get(x);gy=get(y);
		if(gx!=gy)fa[gy]=gx;
		bz[x]=bz[y]=1;
	}
	fo(i,1,cnt)fa[i]=get(fa[i]);
	fo(i,1,cnt)if(bz[i]&&fa[i]==i)ans++;
	if(ans)ans--;
	printf("%d",ans);
	return 0;
}
```