#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define w(x) (x<=n?a[x]:b[x-n-1])
using namespace std;

int n,m,tot,a[100100],b[100100],c[200100],fa[200100],cnt[200100],ans;

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

bool cmp(int x,int y)
{
    return w(x)<w(y);
}

int find(int x)
{
    if (fa[x]==x)
        return x;
    return fa[x]=find(fa[x]);
}

int main()
{
    n=getint();
    repu(i,1,n)
        a[0]^=a[i]=getint();
    repu(i,1,n)
        b[0]^=b[i]=getint();
    repu(i,0,n)
        if (!i || a[i]!=b[i])
            c[++tot]=i,c[++tot]=i+n+1;
    sort(c+1,c+1+tot,cmp);
    int lst=-1;
    repu(i,1,tot)
        m+=w(c[i])!=lst,lst=w(c[i]),w(c[i])=m;
    repu(i,1,m)
        fa[i]=i;
    repu(i,0,n)
        if (a[i]!=b[i])
        {
            ++cnt[a[i]],--cnt[b[i]];
            fa[find(a[i])]=find(b[i]);
        }
    ans=tot/2-2;
    repu(i,1,m)
    {
        ans+=fa[i]==i;
        if (cnt[i])
        {
            puts("-1");
            return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}
### Prompt

Generate 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 <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define w(x) (x<=n?a[x]:b[x-n-1])
using namespace std;

int n,m,tot,a[100100],b[100100],c[200100],fa[200100],cnt[200100],ans;

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

bool cmp(int x,int y)
{
    return w(x)<w(y);
}

int find(int x)
{
    if (fa[x]==x)
        return x;
    return fa[x]=find(fa[x]);
}

int main()
{
    n=getint();
    repu(i,1,n)
        a[0]^=a[i]=getint();
    repu(i,1,n)
        b[0]^=b[i]=getint();
    repu(i,0,n)
        if (!i || a[i]!=b[i])
            c[++tot]=i,c[++tot]=i+n+1;
    sort(c+1,c+1+tot,cmp);
    int lst=-1;
    repu(i,1,tot)
        m+=w(c[i])!=lst,lst=w(c[i]),w(c[i])=m;
    repu(i,1,m)
        fa[i]=i;
    repu(i,0,n)
        if (a[i]!=b[i])
        {
            ++cnt[a[i]],--cnt[b[i]];
            fa[find(a[i])]=find(b[i]);
        }
    ans=tot/2-2;
    repu(i,1,m)
    {
        ans+=fa[i]==i;
        if (cnt[i])
        {
            puts("-1");
            return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}
```