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

cnt, prev_cnt = 0, -1
while cnt != prev_cnt
  prev_cnt = cnt
  N.times do |i|
    adj_sum = B[(i - 1) % N] + B[(i + 1) % N]
    k = (B[i] - A[i]) / adj_sum
    if k > 0
      B[i] -= k * adj_sum
      cnt += k
    end
  end
end

# require 'pry'



if A == B
  puts cnt
else
  puts -1
end






