#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
  char ch;ll f=1;
  while((ch=getchar())<'0'||ch>'9')
   if(ch=='-')f=-1;
  ll res=ch-48;
  while((ch=getchar())>='0'&&ch<='9')
   res=res*10+ch-48;
  return res*f;
} 
const int maxn=100005;
ll n,ans,v,m;
ll a[maxn],b[maxn],c[maxn],d[maxn],fa[maxn];
bool book[maxn];
ll getfa(ll x){
 if(fa[x]==0)return x;
 if(x!=fa[x])fa[x]=getfa(fa[x]);
 return fa[x];
}
map<ll,ll>mp;
int main(){
 n=read();
 for(ll i=1;i<=n;i++)a[i]=read(),v^=a[i],c[i]=a[i];
 a[n+1]=c[n+1]=v;v=0;
 for(ll i=1;i<=n;i++)b[i]=read(),v^=b[i],d[i]=b[i];
 b[++n]=d[n]=v;sort(c+1,c+1+n);sort(d+1,d+1+n);
 for(ll i=1;i<=n;i++){
  if(c[i]!=d[i]){puts("-1");return 0;}
  if(mp[c[i]]==0)mp[c[i]]=++m;
 }
 for(ll i=1;i<=n;i++){
  a[i]=mp[a[i]],b[i]=mp[b[i]];
  if(a[i]!=b[i]){
   if(i<n)ans++;
   ll fx=getfa(a[i]),fy=getfa(b[i]);
   fa[fx]=fy;book[a[i]]=1;book[b[i]]=1;
  }
 }
 if(ans==0)puts("0");
 else{
  book[a[n]]=book[b[n]]=1;
  for(ll i=1;i<=n;i++)
   if(book[i]&&i==getfa(i))
    ans++;
  cout<<ans-1;
 }
 return 0;
}

### Prompt

Construct a cpp code solution to the problem outlined:

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<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
  char ch;ll f=1;
  while((ch=getchar())<'0'||ch>'9')
   if(ch=='-')f=-1;
  ll res=ch-48;
  while((ch=getchar())>='0'&&ch<='9')
   res=res*10+ch-48;
  return res*f;
} 
const int maxn=100005;
ll n,ans,v,m;
ll a[maxn],b[maxn],c[maxn],d[maxn],fa[maxn];
bool book[maxn];
ll getfa(ll x){
 if(fa[x]==0)return x;
 if(x!=fa[x])fa[x]=getfa(fa[x]);
 return fa[x];
}
map<ll,ll>mp;
int main(){
 n=read();
 for(ll i=1;i<=n;i++)a[i]=read(),v^=a[i],c[i]=a[i];
 a[n+1]=c[n+1]=v;v=0;
 for(ll i=1;i<=n;i++)b[i]=read(),v^=b[i],d[i]=b[i];
 b[++n]=d[n]=v;sort(c+1,c+1+n);sort(d+1,d+1+n);
 for(ll i=1;i<=n;i++){
  if(c[i]!=d[i]){puts("-1");return 0;}
  if(mp[c[i]]==0)mp[c[i]]=++m;
 }
 for(ll i=1;i<=n;i++){
  a[i]=mp[a[i]],b[i]=mp[b[i]];
  if(a[i]!=b[i]){
   if(i<n)ans++;
   ll fx=getfa(a[i]),fy=getfa(b[i]);
   fa[fx]=fy;book[a[i]]=1;book[b[i]]=1;
  }
 }
 if(ans==0)puts("0");
 else{
  book[a[n]]=book[b[n]]=1;
  for(ll i=1;i<=n;i++)
   if(book[i]&&i==getfa(i))
    ans++;
  cout<<ans-1;
 }
 return 0;
}

```