import Data.Functor( (<$>))

main = do
    ls <- takeWhile ("0 0"/=) . lines <$> getContents
    let
	nxs = (read <$>) <$> words <$> ls
	
	pick [n,x] = [ (a,b,c)	| a<-[1..n-2] 
				, b<-[a+1..n-1] 
				, c<-[b+1..n]
				, a+b+c==x	]

    (print . length . pick) `mapM_` nxs

