import Control.Applicative

func n x = length [ a | a<-[1..n], b<-[a+1..n], c<-[b+1..n], a+b+c==x ]

main = do
	l <- init . map(map(read::String->Int)) . map words . lines <$> getContents
	let l2 = [ func (t!!0) (t!!1) | t<-l ]
	mapM_ print $ l2