#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[200000],b[200000];
vector<int>E[200000];
bool used[200000];
int deg[200000];

void dfs(int v){
	used[v]=true;
	for(int u:E[v]){
		if(!used[u])dfs(u);
	}
}
int main(){
	int n;cin>>n;
	map<int,int>mp;
	vector<int>vs;
	int x=0;
	rep(i,n){
		scanf("%d",&a[i]);
		mp[a[i]]++;
		x^=a[i];
		vs.push_back(a[i]);
	}
	a[n]=x;
	mp[x]++;
	vs.push_back(x);
	x=0;
	rep(i,n){
		scanf("%d",&b[i]);
		mp[b[i]]--;
		x^=b[i];
	}
	b[n]=x;
	mp[x]--;
	for(auto p:mp){
		if(p.second){
			puts("-1");return 0;
		}
	}
	map<int,vector<int>>want;
	rep(i,n){
		if(a[i]!=b[i]){
			want[b[i]].push_back(i);
		}
	}
	if(want.empty()){
		puts("0");return 0;
	}
	sort(vs.begin(),vs.end());
	vs.erase(unique(vs.begin(),vs.end()),vs.end());
	int cnt=0;
	rep(i,n+1){
		a[i]=lower_bound(vs.begin(),vs.end(),a[i])-vs.begin();
		b[i]=lower_bound(vs.begin(),vs.end(),b[i])-vs.begin();
		if(i==n||a[i]==b[i])continue;
		cnt++;
		E[b[i]].push_back(a[i]);
		E[a[i]].push_back(b[i]);
		deg[a[i]]++;
		deg[b[i]]++;
	}
	int K=0;
	rep(i,vs.size()){
		if(deg[i]&&!used[i]){
			K++;
			dfs(i);
		}
	}
	if(deg[a[n]]){
		cout<<cnt+K-1<<endl;
	}
	else{
		cout<<cnt+K<<endl;
	}
}
### Prompt

Develop a solution in CPP to the problem described below:

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 rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[200000],b[200000];
vector<int>E[200000];
bool used[200000];
int deg[200000];

void dfs(int v){
	used[v]=true;
	for(int u:E[v]){
		if(!used[u])dfs(u);
	}
}
int main(){
	int n;cin>>n;
	map<int,int>mp;
	vector<int>vs;
	int x=0;
	rep(i,n){
		scanf("%d",&a[i]);
		mp[a[i]]++;
		x^=a[i];
		vs.push_back(a[i]);
	}
	a[n]=x;
	mp[x]++;
	vs.push_back(x);
	x=0;
	rep(i,n){
		scanf("%d",&b[i]);
		mp[b[i]]--;
		x^=b[i];
	}
	b[n]=x;
	mp[x]--;
	for(auto p:mp){
		if(p.second){
			puts("-1");return 0;
		}
	}
	map<int,vector<int>>want;
	rep(i,n){
		if(a[i]!=b[i]){
			want[b[i]].push_back(i);
		}
	}
	if(want.empty()){
		puts("0");return 0;
	}
	sort(vs.begin(),vs.end());
	vs.erase(unique(vs.begin(),vs.end()),vs.end());
	int cnt=0;
	rep(i,n+1){
		a[i]=lower_bound(vs.begin(),vs.end(),a[i])-vs.begin();
		b[i]=lower_bound(vs.begin(),vs.end(),b[i])-vs.begin();
		if(i==n||a[i]==b[i])continue;
		cnt++;
		E[b[i]].push_back(a[i]);
		E[a[i]].push_back(b[i]);
		deg[a[i]]++;
		deg[b[i]]++;
	}
	int K=0;
	rep(i,vs.size()){
		if(deg[i]&&!used[i]){
			K++;
			dfs(i);
		}
	}
	if(deg[a[n]]){
		cout<<cnt+K-1<<endl;
	}
	else{
		cout<<cnt+K<<endl;
	}
}
```