i = 0
m = Array.new(100, 0)
n = Array.new
x = Array.new
while n[i-1] != 0 || x[i-1] != 0
	n[i], x[i] = gets.split.map(&:to_i)
	i += 1
end
for o in 0..i-2
	for j in 1..n[o]-2
		for k in j+1..n[o]-1
			for l in k+1..n[o]
				m[o] += 1 if j + k + l == x[o]
			end
		end
	end
	puts m[o]
end