N = gets.chomp.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

Bd = B.each_with_index.map{|x, i| [x, i]}.sort_by{|el| -el[0]}

def max_i arr
  arr.index(arr.max)
end

def binary_insert(a,e)
  index = [*a.each_with_index].bsearch{|x, _| x[0] < e[0]}&.last
  if index
    a.insert(index, e)
  else
    a.push(e)
  end
end


a_max = A.max
cnt = 0
while a_max < B.max
  el, i = Bd.shift
  i1 = (i + 1) % N
  i2 = (i - 1) % N
  B[i] -= (B[i1] + B[i2])
  if B[i] < 0
    puts -1
    exit
  end
  binary_insert Bd, [B[i], i]
  cnt += 1
end

if A == B
  exit
end

puts -1