n = gets.to_i @cheby = gets.strip.split(' ').map(&:to_i) #p @cheby @goal = gets.strip.split(' ').map(&:to_i) #p @goal x, y = 0, 0 points_x = [0] count_x = 0 100.times do next_points_x = [] count_x += 1 points_x.each do |point_x| @cheby.each do |d| next_points_x << point_x - d next_points_x << point_x + d end end if next_points_x.include?(@goal[0]) #p count_x break end #p next_points points_x = next_points_x.uniq end #p points_x points_y = [0] count_y = 0 100.times do next_points_y = [] count_y += 1 points_y.each do |point_y| @cheby.each do |d| next_points_y << point_y - d next_points_y << point_y + d end end if next_points_y.include?(@goal[1]) #p count_y break end #p next_points points_y = next_points_y.uniq end #p points_y p [count_x, count_y].max