import Control.Applicative
import Data.Maybe

countCombi :: Int -> Int -> Maybe Int
countCombi n x
    | n == 0 && x == 0 = Nothing
    | otherwise        = Just $ sum [1 | i <- [1 .. n], j <- [(i + 1) .. n], k <- [(j + 1) .. n], i + j + k == x]

main = do
    combi <- ((\[n, x] -> countCombi n x) . map (read :: String -> Int) . words) <$> getLine
    if (combi == Nothing)
    then return ()
    else do
        putStrLn $ show $ fromJust combi
        main