while line = gets.chomp do
  exit if line == "0 0"
  n, x = line.split(" ").map(&:to_i)
  count = 0
  for i in 1..n do
    for j in i+1..n do
      for k in j+1..n do
        if i+j+k == x then
          count += 1
        end
      end
    end
  end
  printf "%d\n", count
end