Problem:
Score : 1000 points

Problem Statement

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.

Sample Input 1

3
0 1 2
3 1 0

Sample Output 1

2

At first, the XOR of all the elements of a is 3.
If we replace a_1 with 3, a becomes (3, 1, 2).

Now, the XOR of all the elements of a is 0.
If we replace a_3 with 0, a becomes (3, 1, 0), which matches b.

Sample Input 2

3
0 1 2
0 1 2

Sample Output 2

0

Sample Input 3

2
1 1
0 0

Sample Output 3

-1

Sample Input 4

4
0 1 2 3
1 0 3 2

Sample Output 4

5

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define pb push_back
#define mp make_pair
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
#define mx(a,b) (a>b?a:b)
#define mn(a,b) (a<b?a:b)
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;
using namespace std;

namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
	{
		return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
	}
    static char Out[Output],*nowps=Out;
    
    inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

    template<typename T>inline void read(T&x)
	{
		x=0;static char ch;T f=1;
		for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
		for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
		x*=f;
	}

	template<typename T>inline void write(T x,char ch='\n')
	{
		if(!x)*nowps++='0';
		if(x<0)*nowps++='-',x=-x;
		static uint32 sta[111],tp;
		for(tp=0;x;x/=10)sta[++tp]=x%10;
		for(;tp;*nowps++=sta[tp--]^48);
		*nowps++=ch;
	}
}
using namespace IO;

inline void file()
{
#ifndef ONLINE_JUDGE
	FILE*DSD=freopen("duliu.in","r",stdin);
	FILE*FAKE=freopen("duliu.out","w",stdout);
#endif
}

const int MAXN=1e5+7;

static int n;

static int a[MAXN],b[MAXN];

inline void init()
{
	read(n);
	static int x;x=0;
	Rep(i,1,n)read(a[i]),x^=a[i];a[n+1]=x;
	x=0;
	Rep(i,1,n)read(b[i]),x^=b[i];b[n+1]=x;
}

static int ans=-1,e;

static tr1::unordered_map<int,int>G;

static int fa[MAXN<<1];

inline int Find(int u){return u==fa[u]?u:fa[u]=Find(fa[u]);}

static int vis[MAXN<<1];

inline void solve()
{
	Rep(i,1,n)if(!G[a[i]])G[a[i]]=++e;
	Rep(i,1,n)if(!G[b[i]])G[b[i]]=++e;
	Rep(i,1,e)fa[i]=i;
	Rep(i,1,n)if(a[i]^b[i])
	{
		++ans;
		vis[G[a[i]]]=vis[G[b[i]]]=1;
		if(Find(G[a[i]])^Find(G[b[i]]))fa[fa[G[a[i]]]]=fa[G[b[i]]];
	}
	++n;
	sort(a+1,a+n+1),sort(b+1,b+n+1);
	Rep(i,1,n)if(a[i]^b[i])return(void)puts("-1");
	Rep(i,1,e)if(vis[i]&&i==Find(i))++ans;
	printf("%d\n",max(ans,0));
}

int main()
{
    init();
    solve();
    return 0;
}