while line = gets
	n, x = line.split( " " ).map { | val | val.to_i }
	break if 0 == n && 0 == x

	cnt = 0
	for i in ( 1 .. n-2 )
		for j in ( i+1 .. n-1 )
			for k in ( j+1 .. n )
				s = ( i + j + k )
				if x == s
					cnt += 1
					break
				end
			end
		end
	end
	
	puts( cnt )
end