while input = gets

    n, x = input.chomp.split(" ").map(&:to_i)
    
    if n == 0 && x == 0
        exit
    end
    
    ways = 0
    
    for i in 1..n - 2
    
        if i * 3 + 3 > x
            break
        end
    
        for j in i + 1..n - 1
        
            if i + j * 2 + 1 > x
                break
            end
        
            for k in j + 1..n
            
                if i + j + k > x
                    break
                elsif i + j + k == x
                    ways += 1
                end
            end
        end
    end
    
    puts ways
end
