import heapq

def solution(operations):
    answer = []
    min_q = []
    max_q = []
    s_q = {}
    for i in operations :
        op, num = i.split(" ")
        if op == "I" :
            heapq.heappush(min_q, int(num))
            heapq.heappush(max_q, -int(num))
        else :
            while min_q and max_q :
                temp = 0
                if num == "-1" :
                    temp = heapq.heappop(min_q)
                else :
                    temp = -heapq.heappop(max_q)
                if temp in s_q :
                    del s_q[temp]
                    continue
                else :
                    s_q[temp] = 1
                    break
    min_n, max_n = 0,0
    while min_q :
        temp = heapq.heappop(min_q)
        if temp not in s_q : 
            min_n = temp
            break
    while max_q :
        temp = -heapq.heappop(max_q)
        if temp not in s_q : 
            max_n = temp
            break
    return [max_n,min_n]