while ((n,x = gets.split(" ").map(&:to_i)).inject(:+) != 0) do
  max = 3*(n-1)
  if !((6..max).include?(x))
    puts 0
    next
  end
  count = 0
  n.downto(1) do |n1|
    (n1-1).downto(1) do |n2|
      (n2-1).downto(1) do |n3|
        if ((n1 + n2 + n3) == x)
          count += 1
          break
        end
      end
    end
  end
  puts count
end