import sys input=sys.stdin.readline N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) if N==2: if sum(A)==sum(B): print(abs(A[0]-B[0])) else: print(-1) exit() D=[B[i]-A[i] for i in range(N)] X=-sum(D) P=0 for d in D: y=X+(N-2)*d if not(y>=0 and y%(2*(N-2))==0): print(-1) exit() P+=y//(2*(N-2)) print(P)