#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,a[maxn],b[maxn],c[maxn],d[maxn],cnt,n1,n2,nw,fl,f[maxn],t1,t2,ans;

inline int F(int x)
{
	if(f[x]==x) return x;
	return f[x]=F(f[x]);
}

int main()
{
	n=read(); rep(i,1,n) a[i]=read(),n1^=a[i]; rep(i,1,n) b[i]=read(),n2^=b[i];
	a[n+1]=n1; b[n+1]=n2;
	rep(i,1,n) if(a[i]!=b[i]) c[++cnt]=a[i],d[cnt]=b[i],ans++; c[++cnt]=n1; d[cnt]=n2;
	sort(c+1,c+cnt+1); sort(d+1,d+cnt+1);
	rep(i,1,cnt) if(c[i]!=d[i]) {fl=1; break;}
	if(fl) return puts("-1"),0;
	t1=unique(c+1,c+cnt+1)-c-1; rep(i,1,t1) f[i]=i;
	//rep(i,1,t1) cout<<c[i]<<" "; cout<<endl;
	rep(i,1,(n+1))
	{
		if(a[i]!=b[i])
		{
			int x=lower_bound(c+1,c+t1+1,a[i])-c;
			int y=lower_bound(c+1,c+t1+1,b[i])-c;
			int fx=F(x),fy=F(y); if(fx!=fy) f[fx]=fy;
		}
	}
	rep(i,1,t1) if(f[i]==i) ans++; cout<<ans-1<<endl;
	return 0;
}
### 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
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,a[maxn],b[maxn],c[maxn],d[maxn],cnt,n1,n2,nw,fl,f[maxn],t1,t2,ans;

inline int F(int x)
{
	if(f[x]==x) return x;
	return f[x]=F(f[x]);
}

int main()
{
	n=read(); rep(i,1,n) a[i]=read(),n1^=a[i]; rep(i,1,n) b[i]=read(),n2^=b[i];
	a[n+1]=n1; b[n+1]=n2;
	rep(i,1,n) if(a[i]!=b[i]) c[++cnt]=a[i],d[cnt]=b[i],ans++; c[++cnt]=n1; d[cnt]=n2;
	sort(c+1,c+cnt+1); sort(d+1,d+cnt+1);
	rep(i,1,cnt) if(c[i]!=d[i]) {fl=1; break;}
	if(fl) return puts("-1"),0;
	t1=unique(c+1,c+cnt+1)-c-1; rep(i,1,t1) f[i]=i;
	//rep(i,1,t1) cout<<c[i]<<" "; cout<<endl;
	rep(i,1,(n+1))
	{
		if(a[i]!=b[i])
		{
			int x=lower_bound(c+1,c+t1+1,a[i])-c;
			int y=lower_bound(c+1,c+t1+1,b[i])-c;
			int fx=F(x),fy=F(y); if(fx!=fy) f[fx]=fy;
		}
	}
	rep(i,1,t1) if(f[i]==i) ans++; cout<<ans-1<<endl;
	return 0;
}
```