Scanf.scanf "%d %d %d %d %d %d" (fun a b c d e f ->
    let rec loop_n n acc =
        let water = 100 * n * a in
        let rec loop_m m acc =
            let water = water + 100 * m * b in
            let rec loop_x x acc =
                let sugar = x * c in
                let total = water + sugar in
                let rec loop_y y ((s, w) as acc) =
                    let sugar = sugar + y * d in
                    let total = water + sugar in
                    if total > f || 100 * sugar > e * water then loop_x (x + 1) acc else
                        if s * total < sugar * (s + w) then loop_y (y + 1) (sugar, water)
                                                       else loop_y (y + 1) (s, w)
                in
                if total = 0 || total > f || 100 * sugar > e * water then loop_m (m + 1) acc else
                    loop_y 0 acc
            in
            if water > f then loop_n (n + 1) acc else loop_x 0 acc
        in
        if water > f then acc else loop_m 0 acc
    in
    let s, w = loop_n 0 (0, 1) in
    Printf.printf "%d %d\n" (s + w) s
)