#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define Re return
#define In inline
#define inc(l, i, r) for(i=l; i<r; ++i)


const int mxn=1<<17;

int n, a[mxn], b[mxn], f[mxn];
#define Pair pair<int, int>
#define fst first
#define snd second
#define mP make_pair
#define lB lower_bound
Pair a1[mxn], b1[mxn];
char bo[mxn], vis[mxn];

int get(int x){Re f[x]? f[x]=get(f[x]): x;}

In void link(int a, int b)
{
//    printf("%d %d\n", a, b);
    if(get(a+1)!=get(b+1))
        f[get(a+1)]=get(b+1);
}

int main()
{
    int i, j, k, l;
    scanf("%d", &n);
    inc(0, i, n)
        scanf("%d", a+i), a[n]^=a[i];
    inc(0, i, n)
        scanf("%d", b+i), b[n]^=b[i];
    k=n-1;
    inc(j=0, i, n+1)
        if(i<n && a[i]==b[i]) bo[i]=1, --k;
        else
            a1[j  ]=mP(a[i], i),
            b1[j++]=mP(b[i], i);
    
    sort(a1, a1+j), sort(b1, b1+j);
    inc(0, i, j)
        if(a1[i].fst!=b1[i].fst)
            goto NO;

    inc(0, i, n+1)
        if(!bo[i])
            link(i, lB(b1, b1+j, mP(a[i], 0))->snd);
    inc(0, i, j-1)
        if(b1[i].fst==b1[i+1].fst)
            link(b1[i].snd, b1[i+1].snd);

    inc(0, i, n+1)
        if(!bo[i] && !f[i+1])
            ++k;
    
    printf("%d\n", k);
    Re 0;
NO: Re puts("-1"), 0;
}

### Prompt

Please formulate a CPP solution 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<cstring>
#include<algorithm>
using namespace std;

#define Re return
#define In inline
#define inc(l, i, r) for(i=l; i<r; ++i)


const int mxn=1<<17;

int n, a[mxn], b[mxn], f[mxn];
#define Pair pair<int, int>
#define fst first
#define snd second
#define mP make_pair
#define lB lower_bound
Pair a1[mxn], b1[mxn];
char bo[mxn], vis[mxn];

int get(int x){Re f[x]? f[x]=get(f[x]): x;}

In void link(int a, int b)
{
//    printf("%d %d\n", a, b);
    if(get(a+1)!=get(b+1))
        f[get(a+1)]=get(b+1);
}

int main()
{
    int i, j, k, l;
    scanf("%d", &n);
    inc(0, i, n)
        scanf("%d", a+i), a[n]^=a[i];
    inc(0, i, n)
        scanf("%d", b+i), b[n]^=b[i];
    k=n-1;
    inc(j=0, i, n+1)
        if(i<n && a[i]==b[i]) bo[i]=1, --k;
        else
            a1[j  ]=mP(a[i], i),
            b1[j++]=mP(b[i], i);
    
    sort(a1, a1+j), sort(b1, b1+j);
    inc(0, i, j)
        if(a1[i].fst!=b1[i].fst)
            goto NO;

    inc(0, i, n+1)
        if(!bo[i])
            link(i, lB(b1, b1+j, mP(a[i], 0))->snd);
    inc(0, i, j-1)
        if(b1[i].fst==b1[i+1].fst)
            link(b1[i].snd, b1[i+1].snd);

    inc(0, i, n+1)
        if(!bo[i] && !f[i+1])
            ++k;
    
    printf("%d\n", k);
    Re 0;
NO: Re puts("-1"), 0;
}

```