-- Structured Program II - How many ways?

import Control.Applicative

main :: IO ()
main = do
  xs <- map (map read . words) . lines <$> getContents
  mapM_ (print . count) $ takeWhile (/= [0, 0]) xs

count :: [Int] -> Int
count [n, x] = length $ filter (== x) xs
  where xs = [a + b + c | a <- [1 .. n], b <- [a + 1 .. n], c <- [b + 1 .. n]]

