calc :: [Int]->Int
calc [n,x] = length [1|a<-[1..n],b<-[a+1..(min n $ x-a-1)],c<-[b+1..(min n $ x-a-b)],a+b+c==x]

main = getContents >>= mapM_ print.map calc.takeWhile (/= [0,0]).map (map (read :: String->Int).words).lines