while line = gets
	n, x = line.split( " " ).map { | val | val.to_i }
	break if 0 == n && 0 == x

	
	cnt = 0
	ave = x / 3
    for i in ( 1 .. ave-1 )
        for j in ( i+1 .. n-1 )
        	break if x < i+j
            for k in ( j+1 .. n )
                s = ( i + j + k )
                if x < s
                    break
                elsif x == s
                    cnt += 1
                    break
                end
            end
        end
    end

	puts( cnt )
end