import Control.Applicative
import Data.Function
import Control.Monad
import Data.List

f n x = length $ map head . group . sort $ map sort [[a,b,c] | a <- [1..n], b <- [1..n], c <- [1..n]
                 , a+b+c == x
                 , a/=b
                 , b/=c
                 , c/=a
                 ]

r n x = group $ map sort [[a,b,c] | a <- [1..n], b <- [1..n], c <- [1..n]
                 , a+b+c == x
                 , a/=b
                 , b/=c
                 , c/=a
                 ]

main :: IO ()
main = fix $ \loop -> do
    [n,x] <- map read . words <$> getLine
    unless ([n,x] == [0,0]) $ do
        putStrLn . show $ f n x
        loop
