#include <bits/stdc++.h>

typedef std::pair <int, int> pr;
const int N = 100054;

int n, V;
int a[N], b[N];
int ck[N], p[N], size[N];
pr D[N];

int ancestor(int x) {return p[x] == x ? x : (p[x] = ancestor(p[x]));}

inline bool Union(int x, int y) {
	if ((x = ancestor(x)) == (y = ancestor(y))) return true;
	return size[x] < size[y] ? (p[x] = y, size[y] += size[x]) : (p[y] = x, size[x] += size[y]);
}

int main() {
	int i, j, ans = 0; V = 0;
	scanf("%d", &n), ++n;
	for (i = 1; i < n; ++i) scanf("%d", a + i), *a ^= a[i];
	for (i = 1; i < n; ++i) scanf("%d", b + i), *b ^= b[i];
	for (i = 0; i < n; ++i) D[i] = pr(a[i], i);
	std::sort(D, D + n);
	for (i = 0; i < n; ++i) a[D[i].second] = (i && D[i].first == D[i - 1].first ? V - 1 : (D[V] = D[i], V++));
	for (i = 0; i < n; ++i) {
		j = std::lower_bound(D, D + V, pr(b[i], 0)) - D;
		if (j == V || D[j].first != b[i]) return puts("-1"), 0;
		b[i] = j;
	}
	for (i = 0; i < n; ++i) ++ck[a[i]], --ck[b[i]];
	if (std::count(ck, ck + V, 0) != V) return puts("-1"), 0;
	std::iota(p, p + V, 0), std::fill(size, size + V, 1);
	for (i = 0; i < n; ++i) if (a[i] != b[i]) Union(a[i], b[i]), ++ans;
	for (i = 0; i < V; ++i) ans += p[i] == i && size[i] != 1;
	ans -= (*a == *b ? size[ancestor(*a)] != 1 : 2);
	printf("%d\n", ans);
	return 0;
}
### Prompt

Please provide a CPP coded solution 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>

typedef std::pair <int, int> pr;
const int N = 100054;

int n, V;
int a[N], b[N];
int ck[N], p[N], size[N];
pr D[N];

int ancestor(int x) {return p[x] == x ? x : (p[x] = ancestor(p[x]));}

inline bool Union(int x, int y) {
	if ((x = ancestor(x)) == (y = ancestor(y))) return true;
	return size[x] < size[y] ? (p[x] = y, size[y] += size[x]) : (p[y] = x, size[x] += size[y]);
}

int main() {
	int i, j, ans = 0; V = 0;
	scanf("%d", &n), ++n;
	for (i = 1; i < n; ++i) scanf("%d", a + i), *a ^= a[i];
	for (i = 1; i < n; ++i) scanf("%d", b + i), *b ^= b[i];
	for (i = 0; i < n; ++i) D[i] = pr(a[i], i);
	std::sort(D, D + n);
	for (i = 0; i < n; ++i) a[D[i].second] = (i && D[i].first == D[i - 1].first ? V - 1 : (D[V] = D[i], V++));
	for (i = 0; i < n; ++i) {
		j = std::lower_bound(D, D + V, pr(b[i], 0)) - D;
		if (j == V || D[j].first != b[i]) return puts("-1"), 0;
		b[i] = j;
	}
	for (i = 0; i < n; ++i) ++ck[a[i]], --ck[b[i]];
	if (std::count(ck, ck + V, 0) != V) return puts("-1"), 0;
	std::iota(p, p + V, 0), std::fill(size, size + V, 1);
	for (i = 0; i < n; ++i) if (a[i] != b[i]) Union(a[i], b[i]), ++ans;
	for (i = 0; i < V; ++i) ans += p[i] == i && size[i] != 1;
	ans -= (*a == *b ? size[ancestor(*a)] != 1 : 2);
	printf("%d\n", ans);
	return 0;
}
```