selectCombinations :: Int -> Int -> [[Int]]
selectCombinations n x = filter (\[a, b, c] -> a < b && b < c && a+b+c == x) $ sequence [[1..n], [2..n], [3..n]]

main :: IO ()
main = do
    [n, x] <- getLine >>= return.(map $ \n -> read n :: Int).words
    if n == 0 && x == 0 then
        return ()
    else do
        putStrLn $ show $ length $ selectCombinations n x
        main
