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] res = 0.0 for obj in diff: if obj == t: pass else: res += (abs(t) + obj) / 2 if res.is_integer(): r = int(res) if abs(t) == r: print(r) elif r == 0 and abs(t) % (N-2) == 0: print((abs(t) // (N - 2)) * N) elif (r - abs(t)) % (N - 2) == 0: print(r + (r - abs(t)) // (N - 2)) else: print(-1) else: print(-1)