while (n,x = gets.chomp.split.map(&:to_i)) != [0, 0]
  p = 0
  (1..n-2).each do |a|
    (a+1..n-1).each do |b|
      (b+1..n).each do |c|
        p += 1 if a+b+c == x
      end
    end
  end
  puts p
end