{-# LANGUAGE BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Monad.ST
import Control.Monad.State.Strict
import Data.Array.ST
import Data.Array.Unboxed
import Control.Applicative
import Text.Printf
import Debug.Trace


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

main = f =<< replicateM 2 readInt

f [n, x]
  | n == 0 && x == 0 = return ()
  | otherwise = print a >> main
  where a = (flip execState) 0 $ do
                forM_ [1..n] $ \i ->
                    forM_ [i+1..n] $ \j ->
                        let k = x - i - j
                        in when (j < k && k < n) (modify (+1))
