MODE = "stdio"
require 'matrix'
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = "\
  5 9
  5 6
  10 44
  0 0
  ".split("\n")
  tmp.each{|s|
    line << s.strip
  }
end

n,x=[0,0]
i=0
while true
  n,x = line[i].split(" ").map(&:to_i)
  break if n==0 && x==0
  i += 1
  c =  [*1..n].combination(3)
  puts c.select{|a| a.inject(&:+)==x}.size
end