ARGF.each do |line|
n, x = line.split.map(&:to_i)
break if n == 0 && x == 0
ary = []
(1..n).each do |a|
  (1..n).each do |b|
    (1..n).each do |c|
      if a + b + c == x && !(a==b) && !(a==c) && !(b==c)
        ary << [a,b,c].sort
      end
    end
  end
end
  puts ary.uniq.count
end