#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 100005;
int a[MAXN], b[MAXN], par[MAXN], lab[MAXN], n;
unordered_map<int, int> mp, id;

int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }

int main() {
	scanf("%d", &n);
	int tot = 0, x = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		++mp[a[i]];
		if (!id[a[i]]) id[a[i]] = ++tot;
		x ^= a[i];
	}
	++mp[x];
	if (!id[x]) id[x] = ++tot;
	a[n + 1] = x, x = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", b + i);
		if (--mp[b[i]] < 0) return puts("-1"), 0;
		x ^= b[i];
	}
	if (--mp[x] < 0) return puts("-1"), 0;
	b[n + 1] = x;
	for (int i = 1; i <= tot; i++) par[i] = i;
	lab[find(id[a[n + 1]])] = 1;
	int res = 0;
	for (int i = 1; i <= n + 1; i++) {
		if (a[i] == b[i]) continue;
		int p = id[a[i]], q = id[b[i]];
		par[find(p)] = find(q);
		if (i <= n) ++res;
		lab[find(q)] = 1;
	}
	for (int i = 1; i <= tot; i++) res += lab[i] && par[i] == i;
	printf("%d\n", res - 1);
	return 0;
}
### Prompt

Your task is to create 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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 100005;
int a[MAXN], b[MAXN], par[MAXN], lab[MAXN], n;
unordered_map<int, int> mp, id;

int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }

int main() {
	scanf("%d", &n);
	int tot = 0, x = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		++mp[a[i]];
		if (!id[a[i]]) id[a[i]] = ++tot;
		x ^= a[i];
	}
	++mp[x];
	if (!id[x]) id[x] = ++tot;
	a[n + 1] = x, x = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", b + i);
		if (--mp[b[i]] < 0) return puts("-1"), 0;
		x ^= b[i];
	}
	if (--mp[x] < 0) return puts("-1"), 0;
	b[n + 1] = x;
	for (int i = 1; i <= tot; i++) par[i] = i;
	lab[find(id[a[n + 1]])] = 1;
	int res = 0;
	for (int i = 1; i <= n + 1; i++) {
		if (a[i] == b[i]) continue;
		int p = id[a[i]], q = id[b[i]];
		par[find(p)] = find(q);
		if (i <= n) ++res;
		lab[find(q)] = 1;
	}
	for (int i = 1; i <= tot; i++) res += lab[i] && par[i] == i;
	printf("%d\n", res - 1);
	return 0;
}
```