#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<map>
using namespace std;
const int N=1e5+5;
int a[N],b[N],n,X,Y,cnt,tot,head[N],ans;
bool vis[N];
map<int,int>id;
vector<int>va,vb;
struct edge{
	int to,nxt;
}e[N];
inline int get(int x){return id.count(x)?id[x]:id[x]=++tot;}
void dfs(int u){
	vis[u]=1;for(int i=head[u];i;i=e[i].nxt)if(!vis[e[i].to])dfs(e[i].to);
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=0;i<n;++i)cin>>a[i],X^=a[i],va.push_back(a[i]);
	for(int i=0;i<n;++i)cin>>b[i],Y^=b[i],vb.push_back(b[i]);
	va.push_back(X),vb.push_back(Y);
	sort(va.begin(),va.end()),sort(vb.begin(),vb.end());
	if(va!=vb){cout<<"-1\n";return 0;}
	for(int i=0;i<n;++i)
	if(a[i]!=b[i]){
		int A=get(a[i]),B=get(b[i]);
		e[++cnt]=(edge){B,head[A]},head[A]=cnt;
		++ans;
	}
	if(!id.count(X))++ans;else
	if(X!=Y){
		int A=get(X),B=get(Y);
		e[++cnt]=(edge){B,head[A]},head[A]=cnt;
	}
	for(int i=1;i<=tot;++i)if(!vis[i])++ans,dfs(i);
	cout<<ans-1<<'\n';
	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<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<map>
using namespace std;
const int N=1e5+5;
int a[N],b[N],n,X,Y,cnt,tot,head[N],ans;
bool vis[N];
map<int,int>id;
vector<int>va,vb;
struct edge{
	int to,nxt;
}e[N];
inline int get(int x){return id.count(x)?id[x]:id[x]=++tot;}
void dfs(int u){
	vis[u]=1;for(int i=head[u];i;i=e[i].nxt)if(!vis[e[i].to])dfs(e[i].to);
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=0;i<n;++i)cin>>a[i],X^=a[i],va.push_back(a[i]);
	for(int i=0;i<n;++i)cin>>b[i],Y^=b[i],vb.push_back(b[i]);
	va.push_back(X),vb.push_back(Y);
	sort(va.begin(),va.end()),sort(vb.begin(),vb.end());
	if(va!=vb){cout<<"-1\n";return 0;}
	for(int i=0;i<n;++i)
	if(a[i]!=b[i]){
		int A=get(a[i]),B=get(b[i]);
		e[++cnt]=(edge){B,head[A]},head[A]=cnt;
		++ans;
	}
	if(!id.count(X))++ans;else
	if(X!=Y){
		int A=get(X),B=get(Y);
		e[++cnt]=(edge){B,head[A]},head[A]=cnt;
	}
	for(int i=1;i<=tot;++i)if(!vis[i])++ans,dfs(i);
	cout<<ans-1<<'\n';
	return 0;
}
```