#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define N 100005
using namespace std;
int a[N],b[N],n,m,d[N],c[N],n1,f[N];
map <int,int> h;
bool bz[N];
int getf(int k)
{
    if(f[k]==0||f[k]==k) return k;
    return (f[k]=getf(f[k])); 
}
int main()
{
    cin>>n;
    int v=0;
    fo(i,1,n) scanf("%d",&a[i]),v^=a[i],c[i]=a[i];
    a[n+1]=c[n+1]=v;
    bool pd=0;
    v=0;
    fo(i,1,n) scanf("%d",&b[i]),d[i]=b[i],v^=b[i];
    b[++n]=d[n]=v;
    sort(c+1,c+n+1),sort(d+1,d+n+1);
    n1=0;
    fo(i,1,n) 
    {
        if(c[i]!=d[i]) 
        {
            printf("-1\n");
            return 0;
        }
        if(h.count(c[i])==0) h[c[i]]=++n1;
        if(h.count(d[i])==0) h[d[i]]=++n1; 
    }
    int ans=0;
    fo(i,1,n) 
    {
        a[i]=h[a[i]],b[i]=h[b[i]];
        if(a[i]!=b[i]) 
        {
            if(i<n) ans++;
            int fx=getf(a[i]),fy=getf(b[i]);
            f[fx]=fy;
            bz[fx]=1,bz[fy]=1;
        }
    }
    if(ans==0) printf("0\n");
    else
    {
        bz[a[n]]=bz[b[n]]=1;
        fo(i,1,n1) if(bz[i]&&getf(i)==i) ans++;
        printf("%d\n",ans-1);
    }
}
### 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 <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define N 100005
using namespace std;
int a[N],b[N],n,m,d[N],c[N],n1,f[N];
map <int,int> h;
bool bz[N];
int getf(int k)
{
    if(f[k]==0||f[k]==k) return k;
    return (f[k]=getf(f[k])); 
}
int main()
{
    cin>>n;
    int v=0;
    fo(i,1,n) scanf("%d",&a[i]),v^=a[i],c[i]=a[i];
    a[n+1]=c[n+1]=v;
    bool pd=0;
    v=0;
    fo(i,1,n) scanf("%d",&b[i]),d[i]=b[i],v^=b[i];
    b[++n]=d[n]=v;
    sort(c+1,c+n+1),sort(d+1,d+n+1);
    n1=0;
    fo(i,1,n) 
    {
        if(c[i]!=d[i]) 
        {
            printf("-1\n");
            return 0;
        }
        if(h.count(c[i])==0) h[c[i]]=++n1;
        if(h.count(d[i])==0) h[d[i]]=++n1; 
    }
    int ans=0;
    fo(i,1,n) 
    {
        a[i]=h[a[i]],b[i]=h[b[i]];
        if(a[i]!=b[i]) 
        {
            if(i<n) ans++;
            int fx=getf(a[i]),fy=getf(b[i]);
            f[fx]=fy;
            bz[fx]=1,bz[fy]=1;
        }
    }
    if(ans==0) printf("0\n");
    else
    {
        bz[a[n]]=bz[b[n]]=1;
        fo(i,1,n1) if(bz[i]&&getf(i)==i) ans++;
        printf("%d\n",ans-1);
    }
}
```