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

while @pq.size != 0
  k = @pq.peek[1]
  a = B[i(k-1)]
  b = B[k]
  c = B[i(k+1)]

  if B[k] == A[k]
    @pq.poll
  elsif B[k] < A[k]
    puts -1
    exit
  elsif B[k] > A[k]

    @bk = B[k]

    while true

      if B[k] == A[k]
        @pq.poll
        break
      end
      
      if B[k] - (a + c) < A[k]
        if @bk == B[k]
          puts -1
          exit
        end
        @pq.poll
        @pq.add([B[k], k])
        break
      end

      if B[k] - (a + c) >= A[k]
        B[k] -= (a + c)
        @ans += 1
      end
    end
  end
end


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

# binding.pry





