//Heaplax
#include<bits/stdc++.h>
#define N 100005
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,x,ans,cnt,a[N],b[N],fa[N];
map<int,int> s,dy;
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main()
{
	re(n);
	for(int i=1;i<=n;++i)
		re(a[i]),--s[a[i]],x^=a[i];
	for(int i=1;i<=n;++i)
		re(b[i]),++s[b[i]];
	--s[x];
	for(auto i:s)
		if(i.second>0)
			return puts("-1"),0;
	for(int i=1;i<=n;++i)
		if(a[i] != b[i])
		{
			if(!dy[a[i]])dy[a[i]]=++cnt,fa[cnt]=cnt;
			if(!dy[b[i]])dy[b[i]]=++cnt,fa[cnt]=cnt;
			fa[find(dy[a[i]])]=find(dy[b[i]]);
			++ans;
		}
	if(!ans)return puts("0"),0;
	if(!dy[x])++ans;
	--ans;
	for(int i=1;i<=cnt;++i)
		ans+=find(i)==i;
	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
//Heaplax
#include<bits/stdc++.h>
#define N 100005
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,x,ans,cnt,a[N],b[N],fa[N];
map<int,int> s,dy;
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main()
{
	re(n);
	for(int i=1;i<=n;++i)
		re(a[i]),--s[a[i]],x^=a[i];
	for(int i=1;i<=n;++i)
		re(b[i]),++s[b[i]];
	--s[x];
	for(auto i:s)
		if(i.second>0)
			return puts("-1"),0;
	for(int i=1;i<=n;++i)
		if(a[i] != b[i])
		{
			if(!dy[a[i]])dy[a[i]]=++cnt,fa[cnt]=cnt;
			if(!dy[b[i]])dy[b[i]]=++cnt,fa[cnt]=cnt;
			fa[find(dy[a[i]])]=find(dy[b[i]]);
			++ans;
		}
	if(!ans)return puts("0"),0;
	if(!dy[x])++ans;
	--ans;
	for(int i=1;i<=cnt;++i)
		ans+=find(i)==i;
	printf("%d\n",ans);
}

```