Scanf.scanf "%d %d %d %d %d %d" (fun a b c d e f ->
    let rec loop_y water sugar y ((s, w) as acc) =
        let sugar2 = sugar + y * d in
        let total = water + sugar2 in
        if total > f || 100 * sugar2 > e * water then acc else
            let acc = if s * total < sugar2 * (s + w) then sugar2, water else acc in
            loop_y water sugar (y + 1) acc
    in

    let rec loop_x water x acc =
        let sugar = x * c in
        let total = water + sugar in
        if total > f || 100 * sugar > e * water then acc else loop_x water (x + 1) (loop_y water sugar 0 acc)
    in

    let rec loop_m water m acc =
        let water2 = water + 100 * m * b in
        if water2 = 0 || water2 > f then acc else loop_m water (m + 1) (loop_x water2 0 acc)
    in

    let rec loop_n n acc =
        let water = 100 * n * a in
        if water > f then acc else loop_n (n + 1) (loop_m water 0 acc)
    in
    let s, w = loop_n 0 (0, a) in
    Printf.printf "%d %d\n" (s + w) s
)