loop do
  n, x = gets.split.map &:to_i
  break if n == 0 and x == 0
  cnt = 0
  (1..n).each do |i|
    (i+1..n).each do |j|
      (j+1..n).each do |k|
        cnt += 1 if i+j+k == x
      end
    end
  end
  p cnt
end
