from collections import * class Fenwick_Tree: def __init__(self, n): self._n = n self.data = [0] * n def add(self, p, x): assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p - 1] += x p += p & -p def sum(self, l, r): assert 0 <= l <= r <= self._n return self._sum(r) - self._sum(l) def _sum(self, r): s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s def get(self, k): k += 1 x, r = 0, 1 while r < self._n: r <<= 1 len = r while len: if x + len - 1 < self._n: if self.data[x + len - 1] < k: k -= self.data[x + len - 1] x += len len >>= 1 return x N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) DA, DB = [], [] for i in range(N - 1): DA.append(A[i+1]^A[i]) DB.append(B[i+1]^B[i]) if Counter(DA) != Counter(DB): print(-1) exit() ind = defaultdict(list) C = [] for i in range(N-1): ind[DA[i]].append(i) for k, v in ind.items(): ind[k].reverse() for i in range(N-1): C.append(ind[DB[i]].pop()) T = Fenwick_Tree(N - 1) ans = 0 for i in range(N - 1): ans += T.sum(C[i], N - 1) T.add(C[i], 1) print(ans)