N = gets.to_i
A = gets.split.map &:to_i
B = gets.split.map &:to_i
queue = (0...N).sort_by{ |i| -B[i] }
ans = 0
k = N
while j = queue.shift do
  a,b,c = B[(j-1)%N],B[j],B[(j+1)%N]
  if b < A[j]
    p -1; exit
  end
  if b == A[j]
    next
  end
  if a == b || b == c
    p -1; exit
  end

  d = a + c
  x = [a, c].max
  r = b % d
  bb = [x - r, 0].max / d * d + r
  m = (b - bb) / d
  ans += m
  k -= 1
  if m > 0
    k = N
  elsif k == 0
    p -1; exit
  end
  B[j] = bb
  queue << j
  #p [j,B,A,m,k]
end

p (0...N).all?{ |i| A[i] == B[i] } ? ans : -1
