loop do
    n, x = gets.split.map(&:to_i)
    break if n == 0 && x == 0
    res = 0
    [*1..n].combination(3).to_a.each_with_index do |z, index|
        res += 1 if x == z.inject(:+)
    end
    puts res
end
