let rec read u =
    let (num, sum) = Scanf.scanf "%d %d\n" (fun x y -> (x,y)) in
    if num = 0 && sum = 0 then ()
    else
        let n = if num > (sum-3) then sum - 3 else num in
        let m = min (n-1) (sum-n-1) in
        let rec loop ct k l = match k with
            k when k < 3 -> Printf.printf "%d\n" ct
          | k -> ( match l with
                     l when l < 2 -> let m' = min (sum-k) (k-2) in loop ct (k-1) m'
                   | l -> let s = sum-k-l in
                        if s >=1 && s < l then loop (ct+1) k (l-1)
                        else loop ct k (l-1)
                 )
        in loop 0 n m;read u;;
let () = read ();;