#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
int NOEL(){
    cout<<-1<<endl;
    return 0;
}
#define N 100010
ll n,a[N],b[N];
unordered_map<ll,ll> A,B;
bool Cand(){
    a[n]=0;
    lol(i,n)a[n]=a[n] xor a[i];
    lol(i,n+1)A[a[i]]++;
    lol(i,n)B[b[i]]++;
    b[n]=-1;
    lol(i,n+1){
	if(A[a[i]]!=B[a[i]]){
	    if(b[n]!=-1)return 0;
	    b[n]=a[i];
	    B[a[i]]++;
	}
    }
    return 1;
}
unordered_map<ll,vector<ll> > g;
unordered_set<ll> vis;
unordered_set<ll> cur;
void dfs(ll x){
    if(cur.find(x)!=cur.end())return;
    vis.insert(x);
    cur.insert(x);
    for(auto y:g[x])dfs(y);
}
int main(){
    cin>>n;
    lol(i,n)cin>>a[i];
    lol(i,n)cin>>b[i];
    if(!Cand())return NOEL();
    lol(i,n+1){
	if(a[i]!=b[i])g[a[i]].push_back(b[i]);
    }
    ll ans=-2+(a[n]==b[n]);
    lol(i,n+1){
	if(vis.find(a[i])!=vis.end())continue;
	cur.clear();
	dfs(a[i]);
	if(cur.size()==1&&a[i]==a[n])ans++;
	if(cur.size()!=1)ans++;
    }
    for(auto x:vis){
	ans+=g[x].size();
    }
    cout<<ans<<endl;
    return 0;
}

### Prompt

In CPP, your task is to solve 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<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
int NOEL(){
    cout<<-1<<endl;
    return 0;
}
#define N 100010
ll n,a[N],b[N];
unordered_map<ll,ll> A,B;
bool Cand(){
    a[n]=0;
    lol(i,n)a[n]=a[n] xor a[i];
    lol(i,n+1)A[a[i]]++;
    lol(i,n)B[b[i]]++;
    b[n]=-1;
    lol(i,n+1){
	if(A[a[i]]!=B[a[i]]){
	    if(b[n]!=-1)return 0;
	    b[n]=a[i];
	    B[a[i]]++;
	}
    }
    return 1;
}
unordered_map<ll,vector<ll> > g;
unordered_set<ll> vis;
unordered_set<ll> cur;
void dfs(ll x){
    if(cur.find(x)!=cur.end())return;
    vis.insert(x);
    cur.insert(x);
    for(auto y:g[x])dfs(y);
}
int main(){
    cin>>n;
    lol(i,n)cin>>a[i];
    lol(i,n)cin>>b[i];
    if(!Cand())return NOEL();
    lol(i,n+1){
	if(a[i]!=b[i])g[a[i]].push_back(b[i]);
    }
    ll ans=-2+(a[n]==b[n]);
    lol(i,n+1){
	if(vis.find(a[i])!=vis.end())continue;
	cur.clear();
	dfs(a[i]);
	if(cur.size()==1&&a[i]==a[n])ans++;
	if(cur.size()!=1)ans++;
    }
    for(auto x:vis){
	ans+=g[x].size();
    }
    cout<<ans<<endl;
    return 0;
}

```