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