while 1
    n, x = gets.split.map &:to_i
    exit if n == 0 and x == 0
    count = 0
    (1..n).each{ |i|
        ((i+1)..n).each { |j|
            ((j+1)..n).each {|k|
                count += 1 if i != j and j!= k and j != k and i + j + k == x
            }
        }
    }
    puts count
end
