#include<algorithm>
#include<cstring>
#include<cstdio>
#define mxn 1000010
using namespace std;
int n,m,sl,fh,ans,a[mxn],b[mxn],s[mxn],A[mxn],B[mxn],fa[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int getfa(int x)
{
	if(fa[x]!=x) fa[x]=getfa(fa[x]);
	return fa[x];
}
int main()
{
	n=rd();
	for(int i=1;i<=n;++i) a[n+1]^=(a[i]=rd());
	for(int i=1;i<=n;++i) b[n+1]^=(b[i]=rd());
	++n;memcpy(A+1,a+1,n<<2);memcpy(B+1,b+1,n<<2);
	sort(A+1,A+n+1);sort(B+1,B+n+1);
	for(int i=1;i<=n;++i) if(A[i]!=B[i]) return puts("-1"),0;
	for(int i=1;i<n;++i)
		if(a[i]!=b[i])
			++ans,s[++m]=a[i],s[++m]=b[i];
	if(!ans) return puts("0"),0;
	--ans;s[++m]=a[n];s[++m]=b[n];
	sort(s+1,s+m+1);m=unique(s+1,s+m+1)-s-1;
	for(int i=1;i<=m;++i) fa[i]=i;
	int x,y,fx,fy;
	for(int i=1;i<=n;++i)
		if(a[i]!=b[i])
		{
			x=lower_bound(s+1,s+m+1,a[i])-s;
			y=lower_bound(s+1,s+m+1,b[i])-s;
			fx=getfa(x);fy=getfa(y);
			if(fx!=fy) fa[fy]=fx;
		}
	for(int i=1;i<=m;++i)
		if(getfa(i)==i)
			ans++;
	printf("%d\n",ans);
	return 0;
}
### Prompt

Create a solution in CPP for 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<algorithm>
#include<cstring>
#include<cstdio>
#define mxn 1000010
using namespace std;
int n,m,sl,fh,ans,a[mxn],b[mxn],s[mxn],A[mxn],B[mxn],fa[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int getfa(int x)
{
	if(fa[x]!=x) fa[x]=getfa(fa[x]);
	return fa[x];
}
int main()
{
	n=rd();
	for(int i=1;i<=n;++i) a[n+1]^=(a[i]=rd());
	for(int i=1;i<=n;++i) b[n+1]^=(b[i]=rd());
	++n;memcpy(A+1,a+1,n<<2);memcpy(B+1,b+1,n<<2);
	sort(A+1,A+n+1);sort(B+1,B+n+1);
	for(int i=1;i<=n;++i) if(A[i]!=B[i]) return puts("-1"),0;
	for(int i=1;i<n;++i)
		if(a[i]!=b[i])
			++ans,s[++m]=a[i],s[++m]=b[i];
	if(!ans) return puts("0"),0;
	--ans;s[++m]=a[n];s[++m]=b[n];
	sort(s+1,s+m+1);m=unique(s+1,s+m+1)-s-1;
	for(int i=1;i<=m;++i) fa[i]=i;
	int x,y,fx,fy;
	for(int i=1;i<=n;++i)
		if(a[i]!=b[i])
		{
			x=lower_bound(s+1,s+m+1,a[i])-s;
			y=lower_bound(s+1,s+m+1,b[i])-s;
			fx=getfa(x);fy=getfa(y);
			if(fx!=fy) fa[fy]=fx;
		}
	for(int i=1;i<=m;++i)
		if(getfa(i)==i)
			ans++;
	printf("%d\n",ans);
	return 0;
}
```