while xs = gets
    n,x=xs.chomp.split(' ').map{|n| n.to_i}
    count=0
    if n==0 && x==0
        break
    else
        1.upto n do |a|
            (a+1).upto n do |b|
                (b+1).upto n do |c|
                    if a+b+c == x
                        count +=1
                    end
                end
            end
        end
    end
    puts count
end