valid :: Int -> Int -> Int -> Int -> Bool
valid x y z w = x + y + z == w

countTrue :: (Int, Int, Int, Int) -> Int -> Int
countTrue (x, y, z, w) c = if valid x y z w then c + 1 else c

howManyWay :: Int -> Int -> Int
howManyWay n x = foldr countTrue 0 [(i, j, k, x) | i <- [1..n], j <- [1..n], k <- [1..n], j > i, k > j]

main :: IO ()
main = do
  [n, x] <- fmap (map read . words) getLine
  if n == 0 && x == 0
    then return ()
    else do
    print $ howManyWay n x
    main