/*
* @Description: To iterate is human, to recurse divine.
* @Autor: Recursion
* @Date: 2022-03-21 15:45:40
* @LastEditTime: 2022-03-21 16:34:03
*/
#include<bits/stdc++.h>
using namespace std;
int heap[1000005],size;
void push(int x)
{
heap[++size] = x;
int now = size;
while(now > 1){
if(heap[now/2] <= heap[now]) return;
swap(heap[now],heap[now/2]);
now = now/2;
}
}
void pop()
{
int now = 1,next;
heap[1] = heap[size--];
while(now * 2 <=size){
next = now * 2;
if(next + 1 <= size&&heap[next + 1] < heap[next]) next++;//和比较小的儿子交换
if(heap[next] < heap[now]) swap(heap[next],heap[now]);
else break;//交换完成
now = next;
}
}
int main()
{
int n,op;
cin >> n;
while(n--){
cin >> op;
if(op == 1){
int x;
cin >> x;
push(x);
}
if(op == 2){
cout << heap[1] << endl;
}
if(op == 3){
// cout << heap[1] << endl;
pop();
}
}
// for(int i = 1;i <= size;i ++)
// cout << heap[i] << endl;
}