# frozen_string_literal: true class Integer def f A * self**3 + B * self**2 + C * self + D end end def solve (P..Q) .map { { _1 => _1.f } } .reduce(&:merge) .minmax_by { |_k, v| v } .flatten .reverse .join(' ') end A, B, C, D, P, Q = gets.split.map(&:to_i) puts solve