#include <bits/stdc++.h>

#define F(i,a,b) for (int i = a; i <= b; i ++)

const int N = 1e5 + 10;

using namespace std;

int n, m, a[N], b[N], cnt;
int x, y, ans, fa[N], tot; bool bz[N];
struct node {
	int x, num;
	friend bool operator < (node a, node b) { return a.x < b.x; }
} A[N], B[N];

int get(int x) { return !fa[x] ? x : fa[x] = get(fa[x]); }

int main() {
	scanf("%d", &n);
	F(i, 1, n) scanf("%d", &a[i]), x = x ^ a[i]; a[n + 1] = x; x = 0;
	F(i, 1, n) scanf("%d", &b[i]), x = x ^ b[i]; b[n + 1] = x; x = 0;

	F(i, 1, n + 1) A[i] = {a[i], i};
	F(i, 1, n + 1) B[i] = {b[i], i};
	sort(A + 1, A + n + 2);
	sort(B + 1, B + n + 2);

	F(i, 1, n + 1)
		if (A[i].x ^ B[i].x) { puts("-1"); return 0; }
	F(i, 1, n + 1)
		a[A[i].num] = cnt += A[i].x != A[i - 1].x;
	cnt = 0;
	F(i, 1, n + 1)
		b[B[i].num] = cnt += B[i].x != B[i - 1].x;
	
	F(i, 1, n)
		if (a[i] ^ b[i]) {
			x = get(a[i]), y = get(b[i]), ans += (i <= n);
			if (x ^ y) fa[x] = y;
		}
	F(i, 1, n + 1)
		if (a[i] ^ b[i] && (get(a[i]) == a[i]) && !bz[a[i]])
			ans ++, tot ++, bz[a[i]] = 1;
	if (ans == 0) { puts("0"); return 0; }
	ans ++;
	F(i, 1, n)
		if (b[i] == a[n + 1] && a[i] ^ b[i])
			{ ans --; break; }

	printf("%d\n", ans - (tot > 0));
}
### Prompt

Please create a solution in Cpp 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>

#define F(i,a,b) for (int i = a; i <= b; i ++)

const int N = 1e5 + 10;

using namespace std;

int n, m, a[N], b[N], cnt;
int x, y, ans, fa[N], tot; bool bz[N];
struct node {
	int x, num;
	friend bool operator < (node a, node b) { return a.x < b.x; }
} A[N], B[N];

int get(int x) { return !fa[x] ? x : fa[x] = get(fa[x]); }

int main() {
	scanf("%d", &n);
	F(i, 1, n) scanf("%d", &a[i]), x = x ^ a[i]; a[n + 1] = x; x = 0;
	F(i, 1, n) scanf("%d", &b[i]), x = x ^ b[i]; b[n + 1] = x; x = 0;

	F(i, 1, n + 1) A[i] = {a[i], i};
	F(i, 1, n + 1) B[i] = {b[i], i};
	sort(A + 1, A + n + 2);
	sort(B + 1, B + n + 2);

	F(i, 1, n + 1)
		if (A[i].x ^ B[i].x) { puts("-1"); return 0; }
	F(i, 1, n + 1)
		a[A[i].num] = cnt += A[i].x != A[i - 1].x;
	cnt = 0;
	F(i, 1, n + 1)
		b[B[i].num] = cnt += B[i].x != B[i - 1].x;
	
	F(i, 1, n)
		if (a[i] ^ b[i]) {
			x = get(a[i]), y = get(b[i]), ans += (i <= n);
			if (x ^ y) fa[x] = y;
		}
	F(i, 1, n + 1)
		if (a[i] ^ b[i] && (get(a[i]) == a[i]) && !bz[a[i]])
			ans ++, tot ++, bz[a[i]] = 1;
	if (ans == 0) { puts("0"); return 0; }
	ans ++;
	F(i, 1, n)
		if (b[i] == a[n + 1] && a[i] ^ b[i])
			{ ans --; break; }

	printf("%d\n", ans - (tot > 0));
}
```