#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
const int N=1e6+5,M=2e6+5,mo=1e9+7;
map<int,int> Ref;
int n,i,x,a[N],b[N],c[N],d[N],pp,ans,y,fa[N],tt,act[N];
int get(int x)
{
	if (fa[x]==x) return x;
	return fa[x]=get(fa[x]);
}
int main()
{
	scanf("%d",&n);
	fo(i,1,n)
	{
		scanf("%d",a+i);
		x^=a[i];
	}
	a[n+1]=x;x=0;
	fo(i,1,n) 
	{
		scanf("%d",b+i);
		x^=b[i];
	}
	b[++n]=x;
	fo(i,1,n) c[i]=a[i],d[i]=b[i];
	sort(c+1,c+1+n);
	sort(d+1,d+1+n);
	pp=1;
	fo(i,1,n) if (c[i]!=d[i]) break;
	if (i<=n)
		printf("-1\n");
	else
	{
		c[0]=-1;
		fo(i,1,n)
		{
			if (c[i]!=c[i-1]) tt++;
			Ref[c[i]]=tt;
		}
		fo(i,1,tt) fa[i]=i;
		fo(i,1,n)
			if (a[i]!=b[i]||i==n)
			{
				ans+=(i<n);
				act[Ref[a[i]]]=act[Ref[b[i]]]=1;
				fa[get(Ref[a[i]])]=get(Ref[b[i]]);
			}
		if (ans)
		{
			fo(i,1,tt) if (act[i]&&fa[i]==i)
				ans++;
			ans--;
		}	
		printf("%d\n",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<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
const int N=1e6+5,M=2e6+5,mo=1e9+7;
map<int,int> Ref;
int n,i,x,a[N],b[N],c[N],d[N],pp,ans,y,fa[N],tt,act[N];
int get(int x)
{
	if (fa[x]==x) return x;
	return fa[x]=get(fa[x]);
}
int main()
{
	scanf("%d",&n);
	fo(i,1,n)
	{
		scanf("%d",a+i);
		x^=a[i];
	}
	a[n+1]=x;x=0;
	fo(i,1,n) 
	{
		scanf("%d",b+i);
		x^=b[i];
	}
	b[++n]=x;
	fo(i,1,n) c[i]=a[i],d[i]=b[i];
	sort(c+1,c+1+n);
	sort(d+1,d+1+n);
	pp=1;
	fo(i,1,n) if (c[i]!=d[i]) break;
	if (i<=n)
		printf("-1\n");
	else
	{
		c[0]=-1;
		fo(i,1,n)
		{
			if (c[i]!=c[i-1]) tt++;
			Ref[c[i]]=tt;
		}
		fo(i,1,tt) fa[i]=i;
		fo(i,1,n)
			if (a[i]!=b[i]||i==n)
			{
				ans+=(i<n);
				act[Ref[a[i]]]=act[Ref[b[i]]]=1;
				fa[get(Ref[a[i]])]=get(Ref[b[i]]);
			}
		if (ans)
		{
			fo(i,1,tt) if (act[i]&&fa[i]==i)
				ans++;
			ans--;
		}	
		printf("%d\n",ans);
	}
}
```