CODE:
import heapq
n = int(raw_input())
h = []
def min_heapify(A,i):
if i == 0:
left_child = 1
right_child = 2
else:
left_child = (2*i)+1
right_child = left_child+1
if left_child<len(A) and A[left_child]<A[i]:
smallest = left_child
else:
smallest = i
if right_child<len(A) and A[right_child]<A[largest]:
smallest = right_child
if smallest!=i:
(A[smallest],A[i]) = (A[i],A[smallest])
min_heapify(A,smallest)
for _ in range(n):
z=raw_input()
if z[0] == '1' or z[0]=='2':
a,b = map(int,z.split(" "))
if a==1:
heapq.heappush(h,b)
elif a==2:
for i in range(len(h)):
if h[i] == b:
ind = i
break
if ind == len(h)-1:
h.pop()
else:
h[ind] = h[-1]
h.pop()
heapq._siftup(h, ind)
heapq._siftdown(h, 0, ind)
elif z[0]=='3':
print h[0]