main = interact $ show' . solve . read' . lines
  where
    solve = map solveRow
    solveRow [n, x] = sum [1 | a <- [1..n-2], b <- [a+1..n-1], c <- [b+1..n], a + b + c == x]
    show' = unlines . map show
    read' = map (map read . words) . init :: [String] -> [[Int]]
