while (n, x = gets.chomp.split.map(&:to_i)) != [0, 0]
  comb = []
  1.upto(n) do |first|
    1.upto(n) do |second|
      next if second <= first
      1.upto(n) do |third|
        next if third <= second
        comb << [first, second, third] if first + second + third == x
      end
    end
  end
  puts comb.size
end

