#include<map>
#include<cstdio>
#include<algorithm>
#define N 100005
inline int read(){
    int x=0;char ch=getchar();
    for(;ch<48||ch>57;ch=getchar());
    for(;ch>47&&ch<58;ch=getchar())
    x=(x<<1)+(x<<3)+(ch^48);return x;
}
using namespace std;
int s[N],t[N],f[N];
map<int,int>vis,num;
int Fin(int x){return f[x]==x?x:f[x]=Fin(f[x]);}
void merge(int x,int y){
    x=Fin(x),y=Fin(y);
    if(x^y)f[x]=y;
}
int main(){
    int n=read(),sum=0,ans=0,tot=0;
    for(int i=1;i<=n;++i)++vis[s[i]=read()];
    for(int i=1;i<=n;++i)--vis[t[i]=read()];
    for(int i=1;i<=n;++i)sum^=s[i];++vis[sum];
    for(auto v:vis)if(v.second<0)return puts("-1"),0;
    s[n+1]=sum;sum=0;
    for(int i=1;i<=n;++i)sum^=t[i];t[++n]=sum;
    for(int i=1;i<n;++i)
        if(s[i]^t[i]){
            ++ans;
            if(!num[s[i]])num[s[i]]=++tot;
            if(!num[t[i]])num[t[i]]=++tot;
        }
    if(!num[s[n]])num[s[n]]=++tot;
    if(!num[t[n]])num[t[n]]=++tot;
    if(!ans)return puts("0"),0;
    for(int i=1;i<=tot;++i)f[i]=i;
    for(int i=1;i<=n;++i)
        if(s[i]^t[i])
            merge(num[s[i]],num[t[i]]);
    for(int i=1;i<=tot;++i)
        if(f[i]==i)++ans;
    printf("%d\n",ans-1);
    return 0;
}
### Prompt

Please provide a CPP coded solution 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<map>
#include<cstdio>
#include<algorithm>
#define N 100005
inline int read(){
    int x=0;char ch=getchar();
    for(;ch<48||ch>57;ch=getchar());
    for(;ch>47&&ch<58;ch=getchar())
    x=(x<<1)+(x<<3)+(ch^48);return x;
}
using namespace std;
int s[N],t[N],f[N];
map<int,int>vis,num;
int Fin(int x){return f[x]==x?x:f[x]=Fin(f[x]);}
void merge(int x,int y){
    x=Fin(x),y=Fin(y);
    if(x^y)f[x]=y;
}
int main(){
    int n=read(),sum=0,ans=0,tot=0;
    for(int i=1;i<=n;++i)++vis[s[i]=read()];
    for(int i=1;i<=n;++i)--vis[t[i]=read()];
    for(int i=1;i<=n;++i)sum^=s[i];++vis[sum];
    for(auto v:vis)if(v.second<0)return puts("-1"),0;
    s[n+1]=sum;sum=0;
    for(int i=1;i<=n;++i)sum^=t[i];t[++n]=sum;
    for(int i=1;i<n;++i)
        if(s[i]^t[i]){
            ++ans;
            if(!num[s[i]])num[s[i]]=++tot;
            if(!num[t[i]])num[t[i]]=++tot;
        }
    if(!num[s[n]])num[s[n]]=++tot;
    if(!num[t[n]])num[t[n]]=++tot;
    if(!ans)return puts("0"),0;
    for(int i=1;i<=tot;++i)f[i]=i;
    for(int i=1;i<=n;++i)
        if(s[i]^t[i])
            merge(num[s[i]],num[t[i]]);
    for(int i=1;i<=tot;++i)
        if(f[i]==i)++ans;
    printf("%d\n",ans-1);
    return 0;
}
```