#include<bits/stdc++.h>
using namespace std;
int a[3000100],b[3000100],fa[3000100],js[3000100];
map<int,int> mp;
int getf(int s){if (fa[s]==s) return s;return fa[s]=getf(fa[s]);}
int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);mp[a[i]]++;
		a[n+1]^=a[i];
	}
	mp[a[n+1]]++;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);mp[b[i]]--;
		b[n+1]^=b[i];
	}
	mp[b[n+1]]--;
	for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++) if (it->second!=0) {cout<<-1<<endl;return 0;}
	int ans=0;
	for (int i=1;i<=n;i++) if (a[i]!=b[i]) ans++;
	if (ans==0) {cout<<ans<<endl;return 0;}
	mp.clear();for (int i=1;i<=n+1;i++) if ((a[i]!=b[i])||(i==n+1)) mp[a[i]]=mp[b[i]]=0;
	int tp=0;for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++) it->second=++tp;
	for (int i=1;i<=tp;i++) fa[i]=i;
	for (int i=1;i<=n+1;i++) if (a[i]!=b[i]) fa[getf(mp[a[i]])]=getf(mp[b[i]]);
	for (int i=1;i<=tp;i++) ans+=(getf(i)==i);
	cout<<ans-1<<endl;
}
### 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>
using namespace std;
int a[3000100],b[3000100],fa[3000100],js[3000100];
map<int,int> mp;
int getf(int s){if (fa[s]==s) return s;return fa[s]=getf(fa[s]);}
int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);mp[a[i]]++;
		a[n+1]^=a[i];
	}
	mp[a[n+1]]++;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);mp[b[i]]--;
		b[n+1]^=b[i];
	}
	mp[b[n+1]]--;
	for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++) if (it->second!=0) {cout<<-1<<endl;return 0;}
	int ans=0;
	for (int i=1;i<=n;i++) if (a[i]!=b[i]) ans++;
	if (ans==0) {cout<<ans<<endl;return 0;}
	mp.clear();for (int i=1;i<=n+1;i++) if ((a[i]!=b[i])||(i==n+1)) mp[a[i]]=mp[b[i]]=0;
	int tp=0;for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++) it->second=++tp;
	for (int i=1;i<=tp;i++) fa[i]=i;
	for (int i=1;i<=n+1;i++) if (a[i]!=b[i]) fa[getf(mp[a[i]])]=getf(mp[b[i]]);
	for (int i=1;i<=tp;i++) ans+=(getf(i)==i);
	cout<<ans-1<<endl;
}
```