Scanf.scanf "%d %d" (fun k s ->
    let rec loop_z z acc =
        let rec loop_y y acc =
            if y < 0 then acc else
                let x = s - z - y in
                let acc = if x >= 0 && x <= k then acc + 1 else acc in
                loop_y (y - 1) acc
        in
        if z < 0 then acc else loop_z (z - 1) (loop_y k acc)
    in
    loop_z k 0 |> Printf.printf "%d\n"
)