module Main where
import Debug.Trace
import Data.List
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: [[Int]] -> [Int]
solve [] = []
solve ([n, t]:ds) = length (traverse [] 3 [1..n]) : solve ds where
    traverse tc 0 xs = if sum tc == t then [tc] else []
    traverse tc _ [] = []
    traverse tc r (x:xs) = traverse (x:tc) (r-1) xs ++ traverse tc r xs 

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

readUntil :: ([Int] -> Bool) -> IO [[Int]]
readUntil eof = iter where
    iter = readLine >>=
            (\a -> if eof a then return [] else fmap (a:) iter)
            
eof :: [Int] -> Bool
eof (n:x:xs) = all (== 0) [n, x] 

main :: IO() 
main = do
    l   <- readUntil eof
    mapM_ print (solve l)

