c=Array.new()
while true do
  n,x=gets.split(' ')
  n=n.to_i
  x=x.to_i
  if n==0 and x==0 then
     break
  end
  b=Array.new()

  for i in 1..n do
     for j in i+1..n do
        k=x-(i+j)
        if k==i || k==j || i==j || k<i || k<j || k>n then
           next
        else
           a=Array[i,j,k]
           if b.find{|p| p==a}==nil then
              b.push(a)
           end
        end
     end
  end
  c.push(b.length)
end
c.each{|ans|
  printf("%d\n",ans)
}