let range a b = 
    let rec range' j xs =
        if a > j then xs
        else range' (j - 1) (j :: xs) in
    range' b [];;

let take_while f xs =
	let rec take_while' zs = function
		  [] -> List.rev zs
		| (y :: ys) -> if f y then 
						take_while' (y :: zs) ys
					 else
					 	List.rev zs
	in take_while' [] xs
;;


let drop_while f xs =
	let rec drop_while' = function
		  [] -> []
		| (y :: ys) -> if f y then 
						drop_while' ys
					 else
					 	(y :: ys)
	in drop_while' xs
;;

let () =
	let solve n x =
		if 3 * n - 3 < x then print_endline "0"
		else (
			let min_range = range 1 (min (x / 3) (n - 2)) in
			let solve' accum min = 
				let mid_range = range (min + 1) (n - 1) in
				take_while (fun mid -> min + mid * 2 + 1 <= x) mid_range
				|> drop_while (fun mid -> min + mid + n < x) 
				|> List.length 
				|> (+) accum in
			List.fold_left solve' 0 min_range |> Printf.printf "%d\n" ) in
	let rec f _ = 
		let line = Scanf.sscanf (read_line ()) "%d %d" (fun x y -> (x, y)) in
		match line with
			  (0, 0) -> ()
			| (n, x) -> solve n x; f ()
	in f ();;
