#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#define fo(i,a,b) for(register int i=a;i<=b;++i)
#define fod(i,a,b) for(register int i=a;i>=b;--i)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
using namespace std;
const int N=100500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,m1,ans;
int a[N],b[N];
map<int,int>zc;
map<int,int>A;
map<int,bool>z;
int B[2*N][2],B0;
void link(int q,int w)
{
	B[++B0][0]=A[q],A[q]=B0,B[B0][1]=w;
	B[++B0][0]=A[w],A[w]=B0,B[B0][1]=q;
}
void dfs(int q)
{
	z[q]=1;
	efo(i,q)if(!z[B[i][1]])dfs(B[i][1]);
}
int main()
{
	int q,w,e=-1;
	read(n);
	q=w=0;
	fo(i,1,n)q=q^read(a[i]),++zc[a[i]];
	fo(i,1,n)
	{
		if(a[i]!=read(b[i]))
		{
			++ans;
			link(b[i],a[i]);
		}
		if((--zc[b[i]])<0)++w,e=b[i];
	}
	if(!ans)return printf("0\n"),0;
	if(w>1)return printf("-1\n"),0;
	fo(i,1,n)if(a[i]!=b[i]&&!z[b[i]])dfs(b[i]),++ans;
	if(z[q]&&!w||w&&e==q)--ans;
	if(w&&e!=q)printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}
### Prompt

Please create a solution in cpp 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 <cstdlib>
#include <algorithm>
#include <map>
#define fo(i,a,b) for(register int i=a;i<=b;++i)
#define fod(i,a,b) for(register int i=a;i>=b;--i)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
using namespace std;
const int N=100500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,m1,ans;
int a[N],b[N];
map<int,int>zc;
map<int,int>A;
map<int,bool>z;
int B[2*N][2],B0;
void link(int q,int w)
{
	B[++B0][0]=A[q],A[q]=B0,B[B0][1]=w;
	B[++B0][0]=A[w],A[w]=B0,B[B0][1]=q;
}
void dfs(int q)
{
	z[q]=1;
	efo(i,q)if(!z[B[i][1]])dfs(B[i][1]);
}
int main()
{
	int q,w,e=-1;
	read(n);
	q=w=0;
	fo(i,1,n)q=q^read(a[i]),++zc[a[i]];
	fo(i,1,n)
	{
		if(a[i]!=read(b[i]))
		{
			++ans;
			link(b[i],a[i]);
		}
		if((--zc[b[i]])<0)++w,e=b[i];
	}
	if(!ans)return printf("0\n"),0;
	if(w>1)return printf("-1\n"),0;
	fo(i,1,n)if(a[i]!=b[i]&&!z[b[i]])dfs(b[i]),++ans;
	if(z[q]&&!w||w&&e==q)--ans;
	if(w&&e!=q)printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}
```