N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) D=[A[i]-B[i] for i in range(N)] E=sum(D) F=True H=0 for i in range(N): X=E-2*D[i] if X>=0 and X%N==0: H+=X//N else: F=False if F: print(H) else: print(-1)