n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] li = [0]*n ans = 0 for i in range(n): li[i] = b[i]-a[i] li.sort(reverse=True) if li[0] != -li[1]: print(-1) exit() else: ans = li[0] now = -li[0] for i in range(2,n): if now == -li[i]: continue elif abs(now-li[i]) % i == 0: ans += abs(now-li[i]) now = -li[i] else: print(-1) exit() print(ans)