loop do
  n, x = gets.split.map{|str| str.to_i}
  count = 0
  break if n == 0 && x == 0
  for i in (1..n-2)
    for j in (i+1..n-1)
      for k in (j+1..n)
        count += 1 if i+j+k == x
      end
    end
  end
  puts count
end