until (s = gets.chomp) == "0 0" do
    n, x = s.split.map(&:to_i)
    arr = Array.new
    1.upto(n) do |i|
        arr.push(i)
    end
    res = 0
    arr.combination(3) do |item|
        res += 1 if item.inject(:+) == x
    end
    p res
end