#include <bits/stdc++.h>
#define N 1000500
using namespace std;
int a[N],b[N],c[N],d[N],fa[N],n,ans,tot;
map<int,int> mp;
int gf(int x) {return fa[x]==x ? x : fa[x] = gf(fa[x]);}
inline int rd() {int r;scanf("%d",&r);return r;}
int main() {
	n = rd();
	for (int _=1;_<=n;_++) a[_] = rd();
	for (int _=1;_<=n;_++) b[_] = rd();

	for (int _=1;_<=n;_++) a[n+1] ^= a[_], b[n+1] ^= b[_];
	++n;
	for (int _=1;_<=n;_++) c[_] = a[_], d[_] = b[_];

	sort(c+1,c+n+1); sort(d+1,d+n+1);
	for (int _=1;_<=n;_++) if (d[_]!=c[_]) return puts("-1"), 0;
	
	for (int _=1;_<=n;_++) if (a[_] != b[_] || _ == n) {
		_<n ? ++ans :0;
		!mp[ a[_] ] ? mp[ a[_] ] = ++tot :0;
		!mp[ b[_] ] ? mp[ b[_] ] = ++tot :0;
	}
	
	if (!ans) return puts("0"), 0;

	for (int _=1;_<=tot;_++) fa[_] = _;
	for (int _=1;_<n;_++) if (a[_] != b[_])
		fa[ gf( mp[a[_]] ) ] = gf( mp[b[_]] );
	for (int _=1;_<=tot;_++) ans += fa[_] == _;
	cout << ans-1 << endl;

	return 0;
}
### Prompt

Generate 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>
#define N 1000500
using namespace std;
int a[N],b[N],c[N],d[N],fa[N],n,ans,tot;
map<int,int> mp;
int gf(int x) {return fa[x]==x ? x : fa[x] = gf(fa[x]);}
inline int rd() {int r;scanf("%d",&r);return r;}
int main() {
	n = rd();
	for (int _=1;_<=n;_++) a[_] = rd();
	for (int _=1;_<=n;_++) b[_] = rd();

	for (int _=1;_<=n;_++) a[n+1] ^= a[_], b[n+1] ^= b[_];
	++n;
	for (int _=1;_<=n;_++) c[_] = a[_], d[_] = b[_];

	sort(c+1,c+n+1); sort(d+1,d+n+1);
	for (int _=1;_<=n;_++) if (d[_]!=c[_]) return puts("-1"), 0;
	
	for (int _=1;_<=n;_++) if (a[_] != b[_] || _ == n) {
		_<n ? ++ans :0;
		!mp[ a[_] ] ? mp[ a[_] ] = ++tot :0;
		!mp[ b[_] ] ? mp[ b[_] ] = ++tot :0;
	}
	
	if (!ans) return puts("0"), 0;

	for (int _=1;_<=tot;_++) fa[_] = _;
	for (int _=1;_<n;_++) if (a[_] != b[_])
		fa[ gf( mp[a[_]] ) ] = gf( mp[b[_]] );
	for (int _=1;_<=tot;_++) ans += fa[_] == _;
	cout << ans-1 << endl;

	return 0;
}
```