let range start stop =
  let rec iter l i = match i-start with
    | 0 -> start::l
    | _ -> iter (i::l) (i-1)
  in iter [] stop

let find v n x =
  let check v1 v2 x =
    let v3 = x-(v1+v2) in
    v2 < v3 && v3 <= n
  in
  let rec iter i c =
    if i > n then c
    else iter (i+1) (if check v i x then c+1 else c)
  in
  iter (v+1) 0
    

let () =
  let rec loop () =
    match Scanf.scanf "%d %d\n" (fun n x -> n,x) with
    | 0,0 -> ()
    | n,x ->
      let l = range 1 (if n < x/3 then n else x/3) in
      let c = List.fold_left
          (fun acc v -> acc + (find v n x)) 0 l in
      Printf.printf "%d\n" c;
      loop ()
  in
  loop ()