while true do

	inpuLines = gets.split.map(&:to_i);
	
	num = inpuLines[0];
	sum = inpuLines[1];
	
	if num == 0 && sum == 0 then
		break;
	end
	
	count = 0;
	
	for num1 in 1..num do
		for num2 in num1+1..num do
			for num3 in num2+1..num do
				if num1 + num2 + num3 == sum then
					count += 1;
				end
			end
		end
	end
	
	puts count.to_s;
end