Scanf.scanf "%d %d %d %d" (fun a b c x ->
    let rec loop aa acc =
        let rec loop2 bb acc =
            let rec loop3 cc acc =
                if cc > c || aa * 500 + bb * 100 + cc * 50 > x then acc else
                    if aa * 500 + bb * 100 + cc * 50 = x then acc + 1 else
                        loop3 (cc + 1) acc
            in
            if bb > b || aa * 500 + bb * 100 > x then acc else loop2 (bb + 1) (loop3 0 acc)
        in
        if aa > a || aa * 500 > x then acc else loop (aa + 1) (loop2 0 acc)
    in
    loop 0 0 |> Printf.printf "%d\n"
)