while line = gets
  n, x = line.chomp.split.map(&:to_i)
  break if n == 0 && x == 0
  answer = 0
  (1..(n-2)).each do |i|
    ((i+1)..(n-1)).each do |j|
      ((j+1)..n).each do |k|
        if i + j + k == x
          answer += 1
        end
      end
    end
  end
  puts answer
end

