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 else: t = t // (N-2) * N res = calc() if res.is_integer(): r = int(res) if abs(t) == r: result = abs(r) print(result)