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

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

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