#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> g[100002];
bool used[100002];
int ct;
void dfs(int x){
	used[x]=1;
	for(auto y:g[x]){
		if(!used[y]) dfs(y);
	}
}
int main()
{
	int n; cin>>n;
	int a[100002], b[100002], as[100002], bs[100002], s=0;
	map<int, int> mp;
	for(int i=0; i<n; i++){
		cin>>a[i]; as[i]=a[i];
		s^=a[i];
	}
	as[n]=a[n]=s;
	sort(as, as+n+1);
	s=0;
	int ans=0;
	for(int i=0; i<n; i++){
		cin>>b[i]; bs[i]=b[i];
		s^=b[i];
		if(a[i]!=b[i]) mp[b[i]]=0, ans++;
	}
	bs[n]=b[n]=s;
	mp[a[n]]=mp[b[n]]=0;
	sort(bs, bs+n+1);
	for(int i=0; i<=n; i++){
		if(as[i]!=bs[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	if(mp.empty()){
		cout<<0<<endl;
		return 0;
	}
	int c=0;
	for(auto& p:mp){
		p.second=c; c++;
	}
	for(int i=0; i<n; i++){
		int x=mp[a[i]], y=mp[b[i]];
		g[x].push_back(y); g[y].push_back(x);
	}
	for(int i=0; i<c; i++){
		if(!used[i]){
			dfs(i); ct++;
		}
	}
	ans+=(ct-1);
	cout<<ans<<endl;
	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 <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> g[100002];
bool used[100002];
int ct;
void dfs(int x){
	used[x]=1;
	for(auto y:g[x]){
		if(!used[y]) dfs(y);
	}
}
int main()
{
	int n; cin>>n;
	int a[100002], b[100002], as[100002], bs[100002], s=0;
	map<int, int> mp;
	for(int i=0; i<n; i++){
		cin>>a[i]; as[i]=a[i];
		s^=a[i];
	}
	as[n]=a[n]=s;
	sort(as, as+n+1);
	s=0;
	int ans=0;
	for(int i=0; i<n; i++){
		cin>>b[i]; bs[i]=b[i];
		s^=b[i];
		if(a[i]!=b[i]) mp[b[i]]=0, ans++;
	}
	bs[n]=b[n]=s;
	mp[a[n]]=mp[b[n]]=0;
	sort(bs, bs+n+1);
	for(int i=0; i<=n; i++){
		if(as[i]!=bs[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	if(mp.empty()){
		cout<<0<<endl;
		return 0;
	}
	int c=0;
	for(auto& p:mp){
		p.second=c; c++;
	}
	for(int i=0; i<n; i++){
		int x=mp[a[i]], y=mp[b[i]];
		g[x].push_back(y); g[y].push_back(x);
	}
	for(int i=0; i<c; i++){
		if(!used[i]){
			dfs(i); ct++;
		}
	}
	ans+=(ct-1);
	cout<<ans<<endl;
	return 0;
}
```