import Control.Monad
import Control.Applicative

ways n x = let allComb = [(a,b,c) | a <- [1..n], b <- [1..n], c <- [1..n], a < b && b < c] in
    length $ filter (\(l,m,n)->l+m+n == x) allComb

processInputLine [n,x] =
    if n == 0 && x == 0 then return () else print $ ways n x

main = do
    mapM_ processInputLine =<< map (map (read :: String->Int) . words) <$> lines <$> getContents