solve :: [Int] -> Int
solve [n, x] = length $ filter (\y -> x == y) [a + b + c | a <- [1 .. n], b <- [a + 1 .. n], c <- [b + 1 .. n]]

main :: IO ()
main = interact (unlines . map (show . solve) . takeWhile (\xs -> any (/= 0) xs) . map (map read . words) . lines)