#include <bits/stdc++.h>
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second

using namespace std;
typedef pair <int, int> pii;

int arr[301010], brr[301010];
vector <int> ta, tb;

map <int, vector <int> > g;

set <int> chk;
int dfs(int k) {
	if(chk.find(k) != chk.end()) return 0;
	chk.insert(k);
	int ret = 0;
	for(auto i : g[k]) {
		if(i == k) continue;
		ret++;
		ret += dfs(i);
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> arr[i];
		arr[0] ^= arr[i];
		ta.eb(arr[i]);
	}
	ta.eb(arr[0]);
	for(int i = 1; i <= n; i++) {
		cin >> brr[i];
		brr[0] ^= brr[i];
		tb.eb(brr[i]);
	}
	tb.eb(brr[0]);
	sort(all(ta));
	sort(all(tb));

	for(int i = 0; i <= n; i++) {
		if(ta[i] != tb[i]) {
			cout << -1;
			return 0;
		}
	}
	for(int i = 0; i <= n; i++) {
		g[brr[i]].eb(arr[i]);
	}
	int ans = max(1, dfs(arr[0])) - 1;
	if(arr[0] == brr[0] && ans != 0) ans++;
	for(int i = 1; i <= n; i++) {
		if(arr[i] != brr[i] && chk.find(arr[i]) == chk.end()) ans += dfs(arr[i]) + 1;
	}
	cout << ans;
}
### 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>
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second

using namespace std;
typedef pair <int, int> pii;

int arr[301010], brr[301010];
vector <int> ta, tb;

map <int, vector <int> > g;

set <int> chk;
int dfs(int k) {
	if(chk.find(k) != chk.end()) return 0;
	chk.insert(k);
	int ret = 0;
	for(auto i : g[k]) {
		if(i == k) continue;
		ret++;
		ret += dfs(i);
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> arr[i];
		arr[0] ^= arr[i];
		ta.eb(arr[i]);
	}
	ta.eb(arr[0]);
	for(int i = 1; i <= n; i++) {
		cin >> brr[i];
		brr[0] ^= brr[i];
		tb.eb(brr[i]);
	}
	tb.eb(brr[0]);
	sort(all(ta));
	sort(all(tb));

	for(int i = 0; i <= n; i++) {
		if(ta[i] != tb[i]) {
			cout << -1;
			return 0;
		}
	}
	for(int i = 0; i <= n; i++) {
		g[brr[i]].eb(arr[i]);
	}
	int ans = max(1, dfs(arr[0])) - 1;
	if(arr[0] == brr[0] && ans != 0) ans++;
	for(int i = 1; i <= n; i++) {
		if(arr[i] != brr[i] && chk.find(arr[i]) == chk.end()) ans += dfs(arr[i]) + 1;
	}
	cout << ans;
}
```