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
  aj = A[j]
  a,b,c = B[j-1],B[j],B[(j+1)%N]
  if b < aj
    p -1; exit
  end
  if b == aj
    next
  end
  if a == b || b == c
    p -1; exit
  end

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

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