#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B
while true
    n,x = gets.split.map(&:to_i)
    break if n == 0 && x == 0
    
    cnt=0
    for i in 1..n
    for j in (i+1)..n
    for k in (j+1)..n
        cnt+=1 if i+j+k==x
    end
    end
    end
    
    puts cnt
end