a, b, c, d, e = gets.split.map(&:to_i) x = -1 p (1..a * (b - c)).sum { |k| if k == 1 x = d elsif k % 10 != 0 x elsif e <= x x -= e else x end }