while true
    n,x = gets.chomp.split.map(&:to_i)
    break if n.zero? && x.zero?
    count = 0
    for i in 1..n
        for j in (i+1)..n
            for k in (j+1)..n
                count += 1 if x == i + j + k
            end
        end
    end
    puts count
end