import heapq n = int(input()) heap = [] for _ in range(n): inp = [int(i) for i in input().split()] if inp[0] == 1: heapq.heappush(heap, inp[1]) elif inp[0] == 2: print(heap[0]) else: heapq.heappop(heap)