# require 'pry' n = gets.to_i $d = gets.split.map(&:to_i) x,y = gets.split.map(&:to_i) $dm = $d.max M = 1000000000 raise unless n.between?(1, 15) raise unless $d.all? { |d| d.between?(1, M) } raise unless $d.uniq.size == n raise unless x.between?(-M, +M) raise unless y.between?(-M, +M) def solve x if x == 0 0 elsif $d.include? x 1 elsif x <= 2*$dm x == $dm ? 1 : 2 else y = [0, x - (2*$dm)].max jump = (y + $dm - 1) / $dm jump + solve(x - jump*$dm) end end # binding.pry puts solve [x, y].max