while(true)
    n,x=gets.split.map(&:to_i)
    if n==0 && x==0
      exit
    end
    cnt=0
    for i in 1..n
        for j in (i+1)..n
            for k in (j+1)..n
                if i+j+k==x
                    cnt+=1
                end
            end
        end
    end
    p cnt
end
