catch(:stop) do
  while ((n,x = gets.split(" ").map(&:to_i)).inject(:+) != 0) do
    max = 3*(n-1)
    if !((6..max).include?(x))
      puts 0
      throw :stop
    end
    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
end