from sys import stdin from collections import * from heapq import * from random import * input = lambda: stdin.readline().strip() # read1 = stdin.read().split() # idx = 1 h = [] for _ in range(int(input())): x = input().split() if x[0] == "1": heappush(h,int(x[1])) elif x[0] == "2": print(h[0]) else: heappop(h)