#include <cstdio>
#include <algorithm>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=1e5+5;
typedef pair<int,int> Pair;
int n,lst,cn,i,ans,u,v,fa[N],A[N],B[N],C[N*2],a[N],b[N],sz[N];
int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); }
void link(int u,int v)
{
	int fx=find(u),fy=find(v);
	if (fx==fy) return;
	fa[fy]=fx;
	sz[fx]+=sz[fy];
}
int main()
{
//	freopen("xor.in","r",stdin);
//	freopen("xor.out","w",stdout);
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&A[i]),C[++cn]=A[i],A[n+1]^=A[i];
	rep(i,1,n) scanf("%d",&B[i]),C[++cn]=B[i],B[n+1]^=B[i];
	C[++cn]=A[n+1]; C[++cn]=B[n+1];
	sort(C+1,C+1+cn);
	cn=unique(C+1,C+1+cn)-C-1;
	
	rep(i,1,cn) fa[i]=i,sz[i]=1;

	n++;
	lst=lower_bound(C+1,C+1+cn,A[n])-C;
	rep(i,1,n)
		if (A[i]!=B[i]) {
			u=lower_bound(C+1,C+1+cn,A[i])-C;
			v=lower_bound(C+1,C+1+cn,B[i])-C;
			link(u,v);
			if (i!=n) ans++;
		}

	sort(A+1,A+1+n); sort(B+1,B+1+n);
	rep(i,1,n)
		if (A[i]!=B[i]) {
			printf("-1\n"); return 0;
		}
		
	rep(i,1,cn)
		if (fa[i]==i && sz[i]>1) ans++;
	if (fa[lst]==lst && sz[lst]==1) ans++;
	printf("%d\n",ans-1);
	return 0;
}
### 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 <cstdio>
#include <algorithm>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=1e5+5;
typedef pair<int,int> Pair;
int n,lst,cn,i,ans,u,v,fa[N],A[N],B[N],C[N*2],a[N],b[N],sz[N];
int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); }
void link(int u,int v)
{
	int fx=find(u),fy=find(v);
	if (fx==fy) return;
	fa[fy]=fx;
	sz[fx]+=sz[fy];
}
int main()
{
//	freopen("xor.in","r",stdin);
//	freopen("xor.out","w",stdout);
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&A[i]),C[++cn]=A[i],A[n+1]^=A[i];
	rep(i,1,n) scanf("%d",&B[i]),C[++cn]=B[i],B[n+1]^=B[i];
	C[++cn]=A[n+1]; C[++cn]=B[n+1];
	sort(C+1,C+1+cn);
	cn=unique(C+1,C+1+cn)-C-1;
	
	rep(i,1,cn) fa[i]=i,sz[i]=1;

	n++;
	lst=lower_bound(C+1,C+1+cn,A[n])-C;
	rep(i,1,n)
		if (A[i]!=B[i]) {
			u=lower_bound(C+1,C+1+cn,A[i])-C;
			v=lower_bound(C+1,C+1+cn,B[i])-C;
			link(u,v);
			if (i!=n) ans++;
		}

	sort(A+1,A+1+n); sort(B+1,B+1+n);
	rep(i,1,n)
		if (A[i]!=B[i]) {
			printf("-1\n"); return 0;
		}
		
	rep(i,1,cn)
		if (fa[i]==i && sz[i]>1) ans++;
	if (fa[lst]==lst && sz[lst]==1) ans++;
	printf("%d\n",ans-1);
	return 0;
}
```