import Control.Applicative
import Data.List

readInts :: IO [Int]
readInts = map read . words <$> getLine

getLines :: IO [[Int]]
getLines = do
  xs@[a, b] <- readInts
  if a == 0 && b == 0
     then return []
     else do
       rest <- getLines
       return (xs : rest)

calc :: Int -> Int -> Int
calc n x = length [1 | i <- [1..n], j <- [i+1..n], k <- [j+1..n],
                   i + j + k == x]

main :: IO ()
main = do
  xs <- getLines
  putStrLn $ intercalate "\n" [show $ calc n x | [n, x] <- xs]