import sys
import heapq

def insert(heap:list,x:int):
     heapq.heappush(heap,x)
def searchMin(heap:list):
    if len(heap)>0:
        print(heap[0])#输出最小堆的堆顶
def delMin(heap:list):
    if len(heap)>0:
        heapq.heappop(heap)#直接删除最小的
    

n = int(input())
heap = list()#创建最小堆

#将所有op,x都读入
op_x = list(map(int,sys.stdin.read().split()))
#操作指针用于,切换下一个op
ptr = 0
for _ in range(n):

    if op_x[ptr]==1:
        x = op_x[ptr+1]
        S=insert(heap,x)
        ptr+=2
    elif op_x[ptr]==2:
        searchMin(heap)
        ptr+=1

    else:
        delMin(heap)
        ptr+=1