import           Control.Applicative
import           Control.Monad

comb :: Int -> [[Int]]
comb n = [[a, b, c] | a <- [1 .. n], b <- [a + 1 .. n], c <- [b + 1 .. n]]

main :: IO ()
main = do
    xss <- fmap (fmap read . words) . lines <$> getContents :: IO [[Int]]
    let yss = takeWhile (/= [0, 0]) xss
    forM_ yss $ \[n, x] -> do
        print $ length $ filter ((== x) . sum) (comb n)

