class PriorityQueue
  def initialize(array = [])
    @data = []
    array.each{|a| add(a)}
  end
  
  def add(element)
    @data.push(element)
    bottom_up
  end
  
  # @return Integer
  def peek
    @data[0]
  end

  # @return Integer
  def poll
    if size == 0
      return nil
    elsif size == 1
      return @data.pop
    else
      min = @data[0]
      @data[0] = @data.pop
      top_down
      return min
    end
  end
  
  # @return Integer
  def size
    @data.size
  end

  private

  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end

  
  def bottom_up
    idx = size - 1
    while(has_parent?(idx))
      parent_idx = parent_idx(idx)
      if @data[parent_idx].first < @data[idx].first
        swap(parent_idx, idx)
        idx = parent_idx
      else
        return
      end
    end
  end
  
  def top_down
    idx = 0
    while (has_child?(idx))
      a = left_child_idx(idx)
      b = right_child_idx(idx)
      if @data[b].nil?
        c = a
      else
        c = @data[a].first > @data[b].first ? a : b
      end
      if @data[idx].first < @data[c].first
        swap(idx, c)
        idx = c
      else
        return
      end
    end
  end
  

  # @param Integer
  # @return Integer
  def parent_idx(idx)
    (idx - (idx.even? ? 2 : 1)) / 2
  end

  # @param Integer
  # @return Integer
  def left_child_idx(idx)
    (idx * 2) + 1
  end

  # @param Integer
  # @return Integer
  def right_child_idx(idx)
    (idx * 2) + 2
  end

  # @param Integer
  # @return Boolent
  def has_child?(idx)
    ((idx * 2) + 1) < @data.size
  end

  def has_parent?(idx)
    idx > 0
  end
end

# require 'pry'
# pq = PriorityQueue.new([3,4,5,6,7,1,2,3,4])

#################################################################
# Priority Queue
#################################################################


# require 'pry'

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

# print B

def i(i)
  i % N
end

@pq = PriorityQueue.new(B.map.with_index{|v, i| [v, i]})

@ans = 0
@flg = true
while @flg
  @flg = false
  break if @pq.size == 0
  k = @pq.peek[1]
  b_k = B[k]

  
  # binding.pry
  
  
  while true
    
    a = B[i(k-1)]
    b = B[k]
    c = B[i(k+1)]

    if b == A[k]
      @pq.poll
      @flg = true
      break
    end

    if b - (a + c) >= A[k]
      B[k] -= (a + c)
      @ans += 1
      @flg = true
    else
      @pq.poll
      if b_k != B[k]
        @pq.add([B[k], k])
      else
        break if @pq.size == 0
        b_k = @pq.peek[0]
      end
      
      break if @pq.size == 0
      k = @pq.peek[1]
      
    end
    
  end
end

# puts @ans

# require 'pry'



if B == A
  puts @ans
else
  puts -1
end

# binding.pry





