while true
        n,x = gets.split(' ').map(&:to_i)
        break if n == 0 && x == 0
 
        count = 0
        (1..n).each {|i|
                e = i + 1
                (e..n).each {|j|
                        f = j + 1
                        (f..n).each {|k|
                                count += 1 if (i + j + k) == x
                        }
                }
        }
 
        puts count
 
end