while true do
  n, x = gets.split.map(&:to_i)
  break if n == 0 && x == 0

  h = {}

  1.upto(n) do |i|
    1.upto(n) do |j|
      next if i == j
      t = x - (i + j)
      if t > 0 && t < n && t != i && t != j && h[[i,j,t].sort].nil?
        h[[i,j,t].sort] = 1
      end
    end
  end

  puts h.keys.size
end

