import Control.Applicative
import Control.Monad
import Data.Array
import Data.Array.ST
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Text.Printf

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

main :: IO ()
main = do
  [n,x] <- readInts
  when ((n,x) /= (0,0)) $ do
    print $ solve n x
    main

solve :: Int -> Int -> Int
solve n x = length [ (a,b,c) 
                   | a <- [1..n], b <- [a+1..n], c <- [b+1..n]
                   , a + b + c == x
                   ]

