if $stdin.eof?
  $stdin = DATA
end

ARGF.each_line do |line|
  break if line =~ /\A0 0/
  n, x = line.split.map(&:to_i)
  last =
  if n > (x - 3)
    x - 3
  else
    n
  end

  combinations = [*1..last].combination(3)

  puts combinations.select{|arr| arr.inject(:+) == x}.size

end


__END__
5 9
0 0