def solv(n, x)
  ans = []
  (1..n).each do |a|
    (a + 1..n).each do |b|
      (b + 1..n).each do |c|
        ans << [a, b, c] if a + b + c == x
      end
    end
  end
  puts ans.sort.uniq.length
end

loop do
  prob = gets.split.map(&:to_i)
  break if prob == [0, 0]
  solv(*prob)
end