class PriorityQueue
  attr_reader :size

  def initialize(order: :asc)
    @size = 0
    @nodes = []
  end

  def empty?
    @size.zero?
  end

  def push(node)
    index = size
    @size += 1

    while index > 0
      parent = (index - 1) / 2

      break if (@nodes[parent] <=> node) <= 0

      @nodes[index] = @nodes[parent]
      index = parent
    end

    @nodes[index] = node
  end

  alias_method :<<, :push

  def pop
    node = @nodes.first
    root = @nodes[size - 1]
    @size -= 1
    index = 0

    while index * 2 + 1 < @size
      left = 2 * index + 1
      right = left + 1

      if right < size && (@nodes[right] <=> @nodes[left]) <= 0
        left = right
      end

      break if (@nodes[left] <=> root) > 0

      @nodes[index] = @nodes[left]
      index = left
    end

    @nodes[index] = root
    node
  end

  def top
    @nodes.first
  end
end

Node = Struct.new(:v, :i) do
  def <=>(node)
    node.v <=> v
  end
end

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

pque = PriorityQueue.new

B.each_with_index do |b, i|
  pque.push(Node.new(b, i))
end

ans = 0

until pque.empty?
  node = pque.pop

  next if A[node.i] == node.v

  left = (node.i - 1 + N) % N
  right = (node.i + 1) % N

  ok = 0
  d = B[left] + B[right]
  ok = (node.v - A[node.i]) / d

  ans += ok
  v = node.v - ok * (B[left] + B[right])

  if ok == 0 || v < 0
    puts -1
    exit
  end

  B[node.i] = v
  pque.push(Node.new(v, node.i))
end

puts ans
