#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MAXN=110000;
int N;
int a[MAXN];
int b[MAXN];
map<int,vector<int>> posB;
bool was[MAXN];

void dfs(int v) {
	was[v]=true;
	for (int u:posB[a[v]]) if (!was[u]) dfs(u);
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>a[i];
	rep(i,0,N) cin>>b[i];
	
	rep(i,0,N) a[N]^=a[i];
	rep(i,0,N) b[N]^=b[i];
	
	vector<int> vA(a,a+N+1);
	vector<int> vB(b,b+N+1);
	
	if (vA==vB) {
		cout<<"0\n";
		return 0;
	}
	
	sort(vA.begin(),vA.end());
	sort(vB.begin(),vB.end());
	
	if (vA!=vB) {
		cout<<"-1\n";
		return 0;
	}
	
//~ cerr<<a[N]<<endl;
//~ cerr<<b[N]<<endl;
	
	int res=0;
	rep(i,0,N+1) if (a[i]!=b[i]) {
		res++;
		posB[b[i]].push_back(i);
	}
	
	if (a[N]!=b[N]) res--;
	
	int cc=0;
	rep(i,0,N+1) if (a[i]!=b[i] && !was[i]) {
		cc++;
		dfs(i);
	}
	
	res+=cc;
	
	if (a[N]!=b[N] || posB.count(b[N])) {
		res--;
	}

	cout<<res<<"\n";
}

### 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 <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MAXN=110000;
int N;
int a[MAXN];
int b[MAXN];
map<int,vector<int>> posB;
bool was[MAXN];

void dfs(int v) {
	was[v]=true;
	for (int u:posB[a[v]]) if (!was[u]) dfs(u);
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N;
	rep(i,0,N) cin>>a[i];
	rep(i,0,N) cin>>b[i];
	
	rep(i,0,N) a[N]^=a[i];
	rep(i,0,N) b[N]^=b[i];
	
	vector<int> vA(a,a+N+1);
	vector<int> vB(b,b+N+1);
	
	if (vA==vB) {
		cout<<"0\n";
		return 0;
	}
	
	sort(vA.begin(),vA.end());
	sort(vB.begin(),vB.end());
	
	if (vA!=vB) {
		cout<<"-1\n";
		return 0;
	}
	
//~ cerr<<a[N]<<endl;
//~ cerr<<b[N]<<endl;
	
	int res=0;
	rep(i,0,N+1) if (a[i]!=b[i]) {
		res++;
		posB[b[i]].push_back(i);
	}
	
	if (a[N]!=b[N]) res--;
	
	int cc=0;
	rep(i,0,N+1) if (a[i]!=b[i] && !was[i]) {
		cc++;
		dfs(i);
	}
	
	res+=cc;
	
	if (a[N]!=b[N] || posB.count(b[N])) {
		res--;
	}

	cout<<res<<"\n";
}

```