n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
st = 0
ans = 0

finished = [b[i] == a[i] for i in range(n)]
fcount = sum(finished)
while fcount<n and ans>=0:
  for i in range(st,n):
    if not finished[i] and (b[i-1] <= b[i] >= b[(i+1) % n]):
      ans += (b[i]-a[i])//(b[i-1] + b[(i+1) % n])
      b[i] =a[i]+(b[i]-a[i]) % (b[i-1] + b[(i+1) % n])
      
      #print(b)
      if b[i] == a[i]:
        finished[i] = True
        fcount += 1
      elif b[i] < a[i]:
        ans = -1
        break
      st =(i-1)%n
      break
    elif i == n-1:
      st = 0
      
print(ans)
      

