solve :: Int -> Int -> Int
solve n x = length [[a,b,c] | a <- [1..n], b <- [1..n], c <- [1..n], a + b + c == x, a /= b, b /= c, a /= c] `div` 6

main = do
	[n,x] <- fmap (map read . words) getLine
	if [n,x] == [0,0]
		then return ()
		else do
			putStrLn $ show $ solve n x