#include <bits/stdc++.h>
using namespace std;
int a[100500], b[100500];
int mid[100500], mid2[100500];
map<int, int> fa, ok;
int findfa(int x)
{
	if(fa[x] == x) return x;
	return fa[x] = findfa(fa[x]);
}
int main()
{
	fa[-1] = -1;
	int n = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", a + i), a[0] ^= a[i];
	for(int i = 1; i <= n; i++) scanf("%d", b + i), b[0] ^= b[i];
	for(int i = 0; i <= n; i++) mid[i] = a[i], mid2[i] = b[i];
	sort(mid, mid + n + 1), sort(mid2, mid2 + n + 1);
	for(int i = 0; i <= n; i++)
	{
		fa[a[i]] = a[i], fa[b[i]] = b[i];
		if(mid[i] != mid2[i])
		{
			puts("-1");
			return 0;
		}
	}
	int tot = 0;
	for(int i = 0; i <= n; i++)
	{
		if(a[i] != b[i])
		{
			if(i) tot++;
			fa[findfa(a[i])] = findfa(b[i]);
			ok[a[i]] = ok[b[i]] = 1;
		}
	}
	if(tot == 0) cout << 0 << endl;
	if(tot > 0)
	{
		ok[a[0]] = ok[b[0]] = 1;
		for(int i = 0; i <= n; i++)
			if(ok[a[i]] && a[i] == findfa(a[i]))
			{
				tot++;
				fa[a[i]] = -1;
			}
		cout << tot - 1 << endl;
	}
	return 0;
}
//ans=不同位置数+数字的轮换数（包括0）-1
### Prompt

Construct a cpp code solution to the problem outlined:

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;
int a[100500], b[100500];
int mid[100500], mid2[100500];
map<int, int> fa, ok;
int findfa(int x)
{
	if(fa[x] == x) return x;
	return fa[x] = findfa(fa[x]);
}
int main()
{
	fa[-1] = -1;
	int n = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", a + i), a[0] ^= a[i];
	for(int i = 1; i <= n; i++) scanf("%d", b + i), b[0] ^= b[i];
	for(int i = 0; i <= n; i++) mid[i] = a[i], mid2[i] = b[i];
	sort(mid, mid + n + 1), sort(mid2, mid2 + n + 1);
	for(int i = 0; i <= n; i++)
	{
		fa[a[i]] = a[i], fa[b[i]] = b[i];
		if(mid[i] != mid2[i])
		{
			puts("-1");
			return 0;
		}
	}
	int tot = 0;
	for(int i = 0; i <= n; i++)
	{
		if(a[i] != b[i])
		{
			if(i) tot++;
			fa[findfa(a[i])] = findfa(b[i]);
			ok[a[i]] = ok[b[i]] = 1;
		}
	}
	if(tot == 0) cout << 0 << endl;
	if(tot > 0)
	{
		ok[a[0]] = ok[b[0]] = 1;
		for(int i = 0; i <= n; i++)
			if(ok[a[i]] && a[i] == findfa(a[i]))
			{
				tot++;
				fa[a[i]] = -1;
			}
		cout << tot - 1 << endl;
	}
	return 0;
}
//ans=不同位置数+数字的轮换数（包括0）-1
```