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 <= p < self.n, "0<=p 0: s += self.data[r - 1] r -= r & -r return s import collections N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) if A[0] != B[0] or A[N-1] != B[N-1]: print(-1) exit() X = [A[i]^A[i+1] for i in range(N-1)] Y = [B[i]^B[i+1] for i in range(N-1)] if sorted(X) != sorted(Y): print(-1) exit() Z = collections.defaultdict(collections.deque) for i, y in enumerate(Y): Z[y].append(i) A = [] for x in X: A.append(Z[x].popleft()) G = fenwick_tree(N-1) ans = 0 for a in A: ans += G.sum(a+1, N-1) G.add(a, 1) print(ans)