let rec comb n l = match n, l, List.length l with
    | _, [], _ -> []
    | 0, _, _  -> [[]]
    | n, (head::tail), r -> if n = r then [l]
                            else List.append (List.map (fun x -> head :: x) (comb (n-1) tail)) (comb n tail)

let rec range x y = if x > y then [] else x :: range (x+1) y
let sum x = List.fold_left (fun x y -> x + y) 0 x

let () =
  let rec loop () =
    let n, x = Scanf.scanf "%d %d\n" (fun n x -> n, x) in
    if n = 0 && x = 0 then ()
    else (range 1 n
      |> comb 3
      |> List.map sum
      |> List.filter ((=) x)
      |> List.length
      |> Printf.printf "%d\n";
      loop ()) in
  loop ()