#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;

const int MAX_N=1e5;
int N,a[MAX_N+1],b[MAX_N+1];
vector<int> G[MAX_N+1];
bool f[MAX_N+1];
void dfs(int v){
	f[v]=true;
	REP(i,(int)G[v].size()){
		if (!f[G[v][i]]){
			dfs(G[v][i]);
		}
	}
}

int main(){
	cin>>N;
	{
		int xa,xb;
		xa=xb=0;
		REP(i,N){
			cin>>a[i];
			xa^=a[i];
		}
		REP(i,N){
			cin>>b[i];
			xb^=b[i];
		}
		a[N]=xa;
		b[N]=xb;
	}
	{
		map<int,int> ma,mb;
		REP(i,N+1){
			ma[a[i]]++;
			mb[b[i]]++;
		}
		bool flg=true;
		REP(i,N+1){
			if (ma[a[i]]!=mb[a[i]]){
				flg=false;
				break;
			}
		}
		if (!flg){
			cout<<-1<<endl;
			return 0;
		}
	}
	{
		vector<int> vec;
		REP(i,N+1){
			vec.push_back(a[i]);
		}
		sort(vec.begin(),vec.end());
		vec.erase(unique(vec.begin(),vec.end()),vec.end());
		REP(i,N+1){
			a[i]=lower_bound(vec.begin(),vec.end(),a[i])-vec.begin();
			b[i]=lower_bound(vec.begin(),vec.end(),b[i])-vec.begin();
		}
	}
	int edge=0,con=0;
	{
		REP(i,N+1){
			if (a[i]!=b[i] || i==N){
				G[a[i]].push_back(b[i]);
				edge++;
			}
		}
		REP(i,N+1){
			if (G[a[i]].size()!=0 && !f[a[i]]){
				con++;
				dfs(a[i]);
			}
		}
	}
	cout<<edge+con-2<<endl;
	return 0;
}
### Prompt

Your challenge is to write 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 <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;

const int MAX_N=1e5;
int N,a[MAX_N+1],b[MAX_N+1];
vector<int> G[MAX_N+1];
bool f[MAX_N+1];
void dfs(int v){
	f[v]=true;
	REP(i,(int)G[v].size()){
		if (!f[G[v][i]]){
			dfs(G[v][i]);
		}
	}
}

int main(){
	cin>>N;
	{
		int xa,xb;
		xa=xb=0;
		REP(i,N){
			cin>>a[i];
			xa^=a[i];
		}
		REP(i,N){
			cin>>b[i];
			xb^=b[i];
		}
		a[N]=xa;
		b[N]=xb;
	}
	{
		map<int,int> ma,mb;
		REP(i,N+1){
			ma[a[i]]++;
			mb[b[i]]++;
		}
		bool flg=true;
		REP(i,N+1){
			if (ma[a[i]]!=mb[a[i]]){
				flg=false;
				break;
			}
		}
		if (!flg){
			cout<<-1<<endl;
			return 0;
		}
	}
	{
		vector<int> vec;
		REP(i,N+1){
			vec.push_back(a[i]);
		}
		sort(vec.begin(),vec.end());
		vec.erase(unique(vec.begin(),vec.end()),vec.end());
		REP(i,N+1){
			a[i]=lower_bound(vec.begin(),vec.end(),a[i])-vec.begin();
			b[i]=lower_bound(vec.begin(),vec.end(),b[i])-vec.begin();
		}
	}
	int edge=0,con=0;
	{
		REP(i,N+1){
			if (a[i]!=b[i] || i==N){
				G[a[i]].push_back(b[i]);
				edge++;
			}
		}
		REP(i,N+1){
			if (G[a[i]].size()!=0 && !f[a[i]]){
				con++;
				dfs(a[i]);
			}
		}
	}
	cout<<edge+con-2<<endl;
	return 0;
}
```