combinations' :: Int -> [a] -> [[a]]
combinations' n xs = comb n xs [] [] where
  comb 0 _      ys zs = reverse ys : zs
  comb _ []     _  zs = zs
  comb n (x:xs) ys zs = comb (n - 1) xs (x:ys) (comb n xs ys zs)

solve :: [Int] -> Int
solve [n,x] = length $ filter ((== x) . sum) $ combinations' 3 [1..n]
solve _ = undefined

main :: IO ()
main  = getContents
    >>= return . takeWhile (/= [0,0]) . map (map read) . map words . lines
    >>= return . map solve
    >>= mapM_ print