while ((n,x = gets.split(" ").map(&:to_i)).select{|i| i == 0}.length != 2) do
  r = []
  n.downto(1) do |n1|
    (n1-1).downto(1) do |n2|
      (n2-1).downto(1) do |n3|
        r<<[n1,n2,n3] if ((n1 + n2 + n3) == x)
      end
    end
  end
  puts r.length
end