while true
n, x = gets.split.map(&:to_i)
break if n == 0 && x == 0

range = 1..n
box = Array.new
range.each{|number| box << number}

cnt = 0
box.combination(3) {|a, b, c| cnt += 1 if x-a-b-c == 0}

puts cnt
end