while true
  n, x = $stdin.readline.split(" ").map {|s| s.to_i }

  if n == 0 && x == 0
    break
  end

  count = 0
  (1..n-2).each do |i|
    (i+1..n-1).each do |j|
      (j+1..n).each do |k|
        if i + j + k == x then
          count += 1
        end
      end
    end
  end

  puts count
end

