#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<stack>
using namespace std;

int a[100010],b[100010],n;
map<int,int> mp,mp1;
int cnt,tot,fa[200010];
int sz;

int get(int x)
{
	int i=x,j;
	while(fa[x]!=x)	x=fa[x];
	while(fa[i]!=x)	j=fa[i],fa[i]=x,i=j;
	return x;
}

void merge(int x,int y)
{
	x=get(x),y=get(y);
	if(x!=y)	fa[x]=y;
}

int main()
{
	int i,j,k,x=0,ans=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	scanf("%d",&a[i]),x^=a[i],mp[a[i]]++;
	mp[x]++;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		if(!mp[b[i]])	ans=0;
		else	mp[b[i]]--;
	}
	if(!ans)
	{
		printf("-1\n");
		return 0;
	}
	else
	{
		ans=0;
		for(i=1;i<=(n<<1)+1;i++)	fa[i]=i;
		for(i=1;i<=n;i++)
		{
			if(a[i]!=b[i])
			{
				ans++;
				if(!mp1[a[i]])	mp1[a[i]]=++cnt;
				if(!mp1[b[i]])	mp1[b[i]]=++cnt;
				merge(mp1[a[i]],mp1[b[i]]);
			}
		}
		if(!ans)
		{
			printf("0\n");
			return 0;
		}
		if(!mp1[x])	mp1[x]=++cnt;
		for(i=1;i<=cnt;i++)	if(get(i)==i)	ans++;
		printf("%d\n",ans-1);
	}
	return 0;
}
### Prompt

Your challenge is to write 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<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<stack>
using namespace std;

int a[100010],b[100010],n;
map<int,int> mp,mp1;
int cnt,tot,fa[200010];
int sz;

int get(int x)
{
	int i=x,j;
	while(fa[x]!=x)	x=fa[x];
	while(fa[i]!=x)	j=fa[i],fa[i]=x,i=j;
	return x;
}

void merge(int x,int y)
{
	x=get(x),y=get(y);
	if(x!=y)	fa[x]=y;
}

int main()
{
	int i,j,k,x=0,ans=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	scanf("%d",&a[i]),x^=a[i],mp[a[i]]++;
	mp[x]++;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		if(!mp[b[i]])	ans=0;
		else	mp[b[i]]--;
	}
	if(!ans)
	{
		printf("-1\n");
		return 0;
	}
	else
	{
		ans=0;
		for(i=1;i<=(n<<1)+1;i++)	fa[i]=i;
		for(i=1;i<=n;i++)
		{
			if(a[i]!=b[i])
			{
				ans++;
				if(!mp1[a[i]])	mp1[a[i]]=++cnt;
				if(!mp1[b[i]])	mp1[b[i]]=++cnt;
				merge(mp1[a[i]],mp1[b[i]]);
			}
		}
		if(!ans)
		{
			printf("0\n");
			return 0;
		}
		if(!mp1[x])	mp1[x]=++cnt;
		for(i=1;i<=cnt;i++)	if(get(i)==i)	ans++;
		printf("%d\n",ans-1);
	}
	return 0;
}
```