n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

cnt = 0
while b != a
  t = b.index(b.max)
  if b[t] < b[t-1] + b[t+1-b.length]
    puts "-1"
    exit
  end
  cnt += (b[t] / (b[t-1] + b[t+1-b.length]))
  b[t] %= (b[t-1] + b[t+1-b.length])
end
puts cnt
