N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) diff = [] for i in range(N): t = B[i] - A[i] diff.append(t) diff.sort() t = diff[0] def calc(): res = 0.0 for obj in diff: if obj == t: pass else: res += (abs(t) + obj) / 2 return res res = calc() result = -1 if res.is_integer(): r = int(res) if abs(t) == r: result = r elif r == 0: t = t // (N-2) * N res = calc() if res.is_integer(): r = int(res) if abs(t) == r: result = abs(r) else: ta = -diff[0] + diff[N - 1] if ta >= 0: tt = ta * (N-2) for i in range(N): diff[i] += tt t = diff[0] res = calc() if res.is_integer(): r = int(res) if abs(t) == r: result = abs(r + ta * N) print(result)