module Main where

import Data.Functor

main :: IO ()
main =  do
 { nx@[n,x] <- getInts
 ; if nx == [0,0] then done
   else do print $ sum [ 1 | a <- [1..n], b <- [a+1 .. n], c <- [b+1 .. n], x == a+b+c ]
           main
 }

done :: IO ()
done = return ()

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