• + 0 comments

    I learned from Google AI, but I think I improved upon it :)

    import heapq

    myheap = [] heapq.heapify(myheap)

    Q = int(input()) valid = set()

    for _ in range(Q):

    command = [int(i) for i in input().split(' ')]
    
    if command[0] == 1:
        heapq.heappush(myheap, command[1])
        valid.add(command[1])
    elif command[0] == 2:
        valid.remove(command[1])
    elif command[0] == 3:
    
        while True:
            ans = myheap[0]
            if ans in valid:
                print(ans)
                break
            else:
                heapq.heappop(myheap)