import Data.Functor ((<$>))

main :: IO ()
main = do
  [n, x] <- map (read :: String -> Int) . words <$> getLine
  if n == 0 && x == 0
    then return ()
    else do
      print $ length [ (a,b,c) | a <- [1 .. n]
                               , b <- [a+1 .. n]
                               , c <- [b+1 .. n]
                               , a + b + c == x
                     ]
      main

