while line = gets
	num = line.split(" ")
	n,x = num[0].to_i,num[1].to_i
	break if n == 0 && x == 0
	ans = 0
	r = (1..n)
	r.each{|i|
		r.each{|j|
			next if i == j
			r.each{|k|
				next if j == k || i == k
				ans += 1 if i + j + k == x
			}
		}
	}
	p ans / 6
end