n = gets.to_i
h0, a0, d0, s0 = gets.split.map &:to_i

total = 0
arr = []
n.times {
	h, a, d, s = gets.split.map &:to_i
	if a0 - d <= 0
		if a - d0 <= 0
			next
		else
			puts -1
			exit
		end
	end
	arr << [[a - d0, 0].max, (h.to_f/(a0 - d)).ceil]
	total -= [a - d0, 0].max if s < s0
}
arr.sort_by!{|d, c| -d.to_f / c}

turn = 0
arr.each{|d, c|
	total += d * (turn += c)
}

p [h0, total]
puts h0 > total ? total : -1