module Main where

import Control.Applicative
import Numeric

main :: IO ()
main = loop

loop :: IO ()
loop = do
  { [n, x] <- getInts
  ; if n == 0 && x == 0 then return ()
    else print (length (filter ((x ==) . sum) (comb [1..n] 3))) >> loop
  }

comb :: [a] -> Int -> [[a]]
comb ns 0 = [[]]
comb ns k
  | length ns == k = [ns]
  | otherwise      = map (head ns :) (comb (tail ns) (k - 1))
                     ++ comb (tail ns) k

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

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDoubles

showDoubles :: Double -> String
showDoubles d = showFFloat Nothing d ""



