let rec f () =
  let n, x = Scanf.scanf "%d %d\n" (fun a b -> a, b) in
  let ns =
    let rec f n =
      if n = 0 then []
      else n :: f (n-1)
    in
    f n |> Array.of_list
  in
  let res = ref 0 in
  if not (n = 0 && x = 0) then
    begin
      for i = 0 to (n-3) do
        for j = (i + 1) to (n-2) do
          for k = (j + 1) to (n-1) do
            if (ns.(i) + ns.(j) + ns.(k)) = x
            then res := !res + 1
          done
        done
      done;
      print_int !res;
      print_newline();
      f()
    end ;;

f();;
