open Core

let a, b, c, x = Scanf.scanf "%d %d %d %d" (fun a b c x -> (a, b, c, x))

let ar = List.range ~stop:`inclusive 0 a

let br = List.range ~stop:`inclusive 0 b

let cr = List.range ~stop:`inclusive 0 c

let space = List.cartesian_product (List.cartesian_product ar br) cr

let n =
  List.map space ~f:(fun abc ->
      match abc with
      | (a, b), c when (500 * a) + (100 * b) + (50 * c) = x ->
          true
      | _ ->
          false)
  |> List.count ~f:Fn.id

let () = Printf.printf "%d\n" n
