//2018-1-14
//miaomiao
//
#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (100000+5)

int a[N], b[N], m, f[N];
bool num[N];

map<int, int> ms, id;
int Find(int x){return x == f[x]? x: (f[x] = Find(f[x]));}

int main(){
	int n, axor = 0;
	
	scanf("%d", &n);
	For(i, 1, n){
		scanf("%d", &a[i]); axor ^= a[i];
		if(ms.count(a[i])) ++ms[a[i]]; else ms[a[i]] = 1;
	}
	if(ms.count(axor)) ++ms[axor]; else ms[axor] = 1;

	int ans = 0;
	For(i, 1, n){
		scanf("%d", &b[i]);
		if(!ms.count(b[i]) || !ms[b[i]]){puts("-1"); return 0;}
		--ms[b[i]]; if(b[i] != a[i]) ++ans;
	}
	
	For(i, 1, n) if(a[i] != b[i]){
		if(!id.count(a[i])) id[a[i]] = ++m;
		if(!id.count(b[i])) id[b[i]] = ++m;
	}
	if(!id.count(axor)) id[axor] = ++m;

	int u, v;
	For(i, 1, m) f[i] = i;
	For(i, 1, n) if(a[i] != b[i]){
		u = Find(id[a[i]]), v = Find(id[b[i]]);
		if(u != v) f[u] = v;
	}

	num[Find(id[axor])] = true;
	For(i, 1, m) if(!num[Find(i)]){
		num[Find(i)] = true; ++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
//2018-1-14
//miaomiao
//
#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (100000+5)

int a[N], b[N], m, f[N];
bool num[N];

map<int, int> ms, id;
int Find(int x){return x == f[x]? x: (f[x] = Find(f[x]));}

int main(){
	int n, axor = 0;
	
	scanf("%d", &n);
	For(i, 1, n){
		scanf("%d", &a[i]); axor ^= a[i];
		if(ms.count(a[i])) ++ms[a[i]]; else ms[a[i]] = 1;
	}
	if(ms.count(axor)) ++ms[axor]; else ms[axor] = 1;

	int ans = 0;
	For(i, 1, n){
		scanf("%d", &b[i]);
		if(!ms.count(b[i]) || !ms[b[i]]){puts("-1"); return 0;}
		--ms[b[i]]; if(b[i] != a[i]) ++ans;
	}
	
	For(i, 1, n) if(a[i] != b[i]){
		if(!id.count(a[i])) id[a[i]] = ++m;
		if(!id.count(b[i])) id[b[i]] = ++m;
	}
	if(!id.count(axor)) id[axor] = ++m;

	int u, v;
	For(i, 1, m) f[i] = i;
	For(i, 1, n) if(a[i] != b[i]){
		u = Find(id[a[i]]), v = Find(id[b[i]]);
		if(u != v) f[u] = v;
	}

	num[Find(id[axor])] = true;
	For(i, 1, m) if(!num[Find(i)]){
		num[Find(i)] = true; ++ans;
	}
	printf("%d\n", ans);

	return 0;
}
```