#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
 
using namespace std;
 
const int N=100005;
 
int n,s1[N],m1,s2[N],m2,vec[N];
int A[N],B[N],ans,fa[N],m,sz[N];
bool fl[N];
map<int,int> D;

inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline void link(int u,int v){if(find(u)!=find(v))sz[find(v)]+=sz[find(u)],fa[find(u)]=find(v);}
 
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&s1[i]),m1^=s1[i],D[s1[i]]++;
	D[m1]++;
	for(int i=1;i<=n;i++)scanf("%d",&s2[i]),m2^=s2[i],D[s2[i]]--;
	for(auto&i:D)if(i.se<0)puts("-1"),exit(0);
	s1[0]=m1;s2[0]=m2;
	memcpy(vec,s1,(n+1)<<2);
	sort(vec,vec+n+1);
	m=unique(vec,vec+n+1)-vec;
	for(int i=0;i<m;i++)fa[i]=i,sz[i]=1;
	for(int i=0;i<=n;i++){
		A[i]=lower_bound(vec,vec+m,s1[i])-vec;
		B[i]=lower_bound(vec,vec+m,s2[i])-vec;
		if(A[i]!=B[i])link(A[i],B[i]),ans++;
	}
	if(!ans)puts("0"),exit(0);
	if(A[0]!=B[0])ans--;
	for(int i=0;i<m;i++){
		if(fa[i]==i&&sz[i]>1){
			fl[find(i)]=true;
			if(find(i)!=find(A[0])&&find(i)!=find(B[0]))ans++;
		}
	}
	printf("%d\n",ans);
	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
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
 
using namespace std;
 
const int N=100005;
 
int n,s1[N],m1,s2[N],m2,vec[N];
int A[N],B[N],ans,fa[N],m,sz[N];
bool fl[N];
map<int,int> D;

inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline void link(int u,int v){if(find(u)!=find(v))sz[find(v)]+=sz[find(u)],fa[find(u)]=find(v);}
 
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&s1[i]),m1^=s1[i],D[s1[i]]++;
	D[m1]++;
	for(int i=1;i<=n;i++)scanf("%d",&s2[i]),m2^=s2[i],D[s2[i]]--;
	for(auto&i:D)if(i.se<0)puts("-1"),exit(0);
	s1[0]=m1;s2[0]=m2;
	memcpy(vec,s1,(n+1)<<2);
	sort(vec,vec+n+1);
	m=unique(vec,vec+n+1)-vec;
	for(int i=0;i<m;i++)fa[i]=i,sz[i]=1;
	for(int i=0;i<=n;i++){
		A[i]=lower_bound(vec,vec+m,s1[i])-vec;
		B[i]=lower_bound(vec,vec+m,s2[i])-vec;
		if(A[i]!=B[i])link(A[i],B[i]),ans++;
	}
	if(!ans)puts("0"),exit(0);
	if(A[0]!=B[0])ans--;
	for(int i=0;i<m;i++){
		if(fa[i]==i&&sz[i]>1){
			fl[find(i)]=true;
			if(find(i)!=find(A[0])&&find(i)!=find(B[0]))ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}
```