#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t;o=E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
const int N=400010;
int vis[N],ft[N],n,ans,sa,sb,tot,a[N],b[N],cnt[N];
map <int,int> mp;
map <int,int> :: iterator it;
struct edge{int t,n;}E[N<<2];
void dfs(int u){
	vis[u]=1;
	go(u) if (!vis[v]) dfs(v);
}
void add(int u,int v){
	E[++tot]=(edge){v,ft[u]},ft[u]=tot;
}
int main(){
//	freopen("t.txt","r",stdin);
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i),sa^=a[i],mp[a[i]];
	rep(i,1,n) scanf("%d",b+i),sb^=b[i],mp[b[i]];
	mp[sa],mp[sb];
	int __=0; for (it=mp.begin();it!=mp.end();it++) it->se=++__;
	rep(i,1,n) a[i]=mp[a[i]],b[i]=mp[b[i]];
	sa=mp[sa],sb=mp[sb];
	add(sa,sb),add(sb,sa);
	rep(i,1,n) add(a[i],b[i]),add(b[i],a[i]),ans-=a[i]==b[i];
	ans+=n;
	rep(i,1,n) if (a[i]!=b[i]) --cnt[b[i]];
	if (cnt[sa]) ans--;
	rep(i,1,n) if (a[i]!=b[i]) ++cnt[a[i]];
	++cnt[sa],--cnt[sb];
	rep(i,1,n*2+3) if (cnt[i]) return puts("-1"),0;
	rep(i,1,__) if (!vis[i]){
		go(i) if (v!=i) goto cc;
		continue;
	cc:	++ans;
		dfs(i);
	}
	printf("%d\n",ans);
	return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

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<algorithm>
#include<map>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t;o=E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
const int N=400010;
int vis[N],ft[N],n,ans,sa,sb,tot,a[N],b[N],cnt[N];
map <int,int> mp;
map <int,int> :: iterator it;
struct edge{int t,n;}E[N<<2];
void dfs(int u){
	vis[u]=1;
	go(u) if (!vis[v]) dfs(v);
}
void add(int u,int v){
	E[++tot]=(edge){v,ft[u]},ft[u]=tot;
}
int main(){
//	freopen("t.txt","r",stdin);
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i),sa^=a[i],mp[a[i]];
	rep(i,1,n) scanf("%d",b+i),sb^=b[i],mp[b[i]];
	mp[sa],mp[sb];
	int __=0; for (it=mp.begin();it!=mp.end();it++) it->se=++__;
	rep(i,1,n) a[i]=mp[a[i]],b[i]=mp[b[i]];
	sa=mp[sa],sb=mp[sb];
	add(sa,sb),add(sb,sa);
	rep(i,1,n) add(a[i],b[i]),add(b[i],a[i]),ans-=a[i]==b[i];
	ans+=n;
	rep(i,1,n) if (a[i]!=b[i]) --cnt[b[i]];
	if (cnt[sa]) ans--;
	rep(i,1,n) if (a[i]!=b[i]) ++cnt[a[i]];
	++cnt[sa],--cnt[sb];
	rep(i,1,n*2+3) if (cnt[i]) return puts("-1"),0;
	rep(i,1,__) if (!vis[i]){
		go(i) if (v!=i) goto cc;
		continue;
	cc:	++ans;
		dfs(i);
	}
	printf("%d\n",ans);
	return 0;
}

```