while !((n, x = gets.split.map(&:to_i)).all?(&:zero?))
  num_array = (1..n).to_a
  count = 0
  comb = []
  num_array.each do |f|
    (f..n).each do |s|
      (s..n).each do |t|
        if f + s + t == x && ([f, s, t].count - [f, s, t].uniq.count) == 0
          count += 1
        elsif f + s + t > x
          break
        end
      end
    end
  end
  puts count
end
