#include <bits/stdc++.h>

void open() {
	freopen("duliu.in", "r", stdin);
	freopen("duliu.out", "w", stdout);
}

const int MAXN = 100000 + 5;

int N, A[MAXN], B[MAXN];
std::map<int, int> Cnt, M;
std::set<int> S;

int num, Fa[MAXN];

int findFa(int x) {
	return Fa[x] == x ? x : Fa[x] = findFa(Fa[x]);
}

void merge(int x, int y) {
	x = findFa(x), y = findFa(y);
	if (x == y) {
		return ;
	}
	Fa[y] = x;
	--num;
}

int main() {
	// open();
	scanf("%d", &N);
	int x = 0;
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &A[i]);
		Cnt[A[i]]++;
		x ^= A[i];
	}
	Cnt[x]++;
	S.insert(x);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &B[i]);
		if (--Cnt[B[i]] < 0) {
			puts("-1");
			return 0;
		}
		if (A[i] != B[i]) {
			S.insert(A[i]);
			S.insert(B[i]);
		}
	}
	int cnt = 0;
	for (std::set<int>::iterator p = S.begin(); p != S.end(); ++p) {
		M[*p] = ++cnt;	
	}
	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		if (A[i] != B[i]) {
			if (!Fa[M[A[i]]]) {
				Fa[M[A[i]]] = M[A[i]];
				++num;
			}
			if (!Fa[M[B[i]]]) {
				Fa[M[B[i]]] = M[B[i]];
				++num;
			}
		}
	}
	if(!Fa[M[x]]) {
		Fa[M[x]] = M[x];
		++num;
	}
	for (int i = 1; i <= N; ++i) {
		if (A[i] != B[i]) {
			merge(M[A[i]], M[B[i]]);
			++ans;
		}
	}
	ans += num;
	printf("%d\n", ans - 1);
	return 0;
}
### Prompt

Develop a solution in CPP 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>

void open() {
	freopen("duliu.in", "r", stdin);
	freopen("duliu.out", "w", stdout);
}

const int MAXN = 100000 + 5;

int N, A[MAXN], B[MAXN];
std::map<int, int> Cnt, M;
std::set<int> S;

int num, Fa[MAXN];

int findFa(int x) {
	return Fa[x] == x ? x : Fa[x] = findFa(Fa[x]);
}

void merge(int x, int y) {
	x = findFa(x), y = findFa(y);
	if (x == y) {
		return ;
	}
	Fa[y] = x;
	--num;
}

int main() {
	// open();
	scanf("%d", &N);
	int x = 0;
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &A[i]);
		Cnt[A[i]]++;
		x ^= A[i];
	}
	Cnt[x]++;
	S.insert(x);
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &B[i]);
		if (--Cnt[B[i]] < 0) {
			puts("-1");
			return 0;
		}
		if (A[i] != B[i]) {
			S.insert(A[i]);
			S.insert(B[i]);
		}
	}
	int cnt = 0;
	for (std::set<int>::iterator p = S.begin(); p != S.end(); ++p) {
		M[*p] = ++cnt;	
	}
	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		if (A[i] != B[i]) {
			if (!Fa[M[A[i]]]) {
				Fa[M[A[i]]] = M[A[i]];
				++num;
			}
			if (!Fa[M[B[i]]]) {
				Fa[M[B[i]]] = M[B[i]];
				++num;
			}
		}
	}
	if(!Fa[M[x]]) {
		Fa[M[x]] = M[x];
		++num;
	}
	for (int i = 1; i <= N; ++i) {
		if (A[i] != B[i]) {
			merge(M[A[i]], M[B[i]]);
			++ans;
		}
	}
	ans += num;
	printf("%d\n", ans - 1);
	return 0;
}
```