Scanf.scanf "%d %d %d %d %d %d" (fun a b c d p q -> let rec loop x mix miy mxx mxy = if x > q then Printf.printf "%d %d %d %d\n" mxy mxx miy mix else let y = a * x * x * x + b * x * x + c * x + d in let mix, miy = if y < miy then x, y else mix, miy in let mxx, mxy = if y > mxy then x, y else mxx, mxy in loop (x + 1) mix miy mxx mxy in loop p 0 max_int 0 min_int )