class fenwick_tree(): n=1 data=[0 for i in range(n)] def __init__(self,N): self.n=N self.data=[0 for i in range(N)] def add(self,p,x): assert 0<=p0): s+=self.data[r-1] r-=r&-r return s N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) A2 = [] for i in range(N-1): A2.append(A[i]^A[i+1]) B2 = [] for i in range(N-1): B2.append(B[i]^B[i+1]) if sorted(A2) != sorted(B2): print(-1) exit() M = {} for b in B2: M[b] = [] for i, b in enumerate(B2): M[b].append(i) C = [-1] * (N-1) for i, a in enumerate(A2[::-1]): C[N-2-i] = M[a][-1] M[a].pop() bit = fenwick_tree(N) ans = 0 for c in C: ans += bit.sum(c+1, N) bit.add(c, 1) print(ans)