import Control.Applicative

type Data = (Int, Int)

type Problem = [Data]

type Result = [Int]

count :: Data -> Int

count (n, x)
    = length $ filter (\(m, l, o) -> m + l + o == x) sets where
        sets = concat.concat $ [[[(m, l, o) | o <- [(l + 1)..n]] | l <- [(m + 1)..n]] | m <- [1..n]]

solve :: Problem -> Result

solve xs
    = map count xs

output :: Result -> String

output xs
    = concat $ map (\x -> show x ++ "\n") xs
    
input :: IO Problem

input
    = return =<< inputProblem []
    
inputProblem :: Problem -> IO Problem

inputProblem xs
    = do
        [n, x] <- map read.words <$> getLine
        if (n, x) /= (0, 0)
            then inputProblem $ xs ++ [(n, x)]
            else return xs
    
main :: IO ()

main
    = putStr.output =<< solve <$> input