#include<bits/stdc++.h>
#define f(x) ((x)/2)
#define g(x) ((x)*2)
#define d(x) ((x)*2+1)
using namespace std;
int siz;
int heap[1000001];
void push(int x)
{
int pos=siz++;
while(pos>0)
{
if(heap[f(pos)]<=x)
{
break;
}
heap[pos]=heap[f(pos)],pos=f(pos);
}
heap[pos]=x;
return ;
}
void pop()
{
int pos=0,x=heap[--siz];
while(g(pos)<siz)
{
int t=(heap[g(pos)]<heap[d(pos)])?g(pos): d(pos);
if(heap[t]>=x)
{
break;
}
heap[pos]=heap[t],pos=t;
}
heap[pos]=x;
return ;
}
int top()
{
return heap[0];
}
int n,op,x;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n;
while(n--)
{
cin>>op;
if(op==1)
{
cin>>x;
push(x);
}
if(op==2)
{
cout<<top()<<endl;
}
if(op==3)
{
pop();
}
}
return 0;
}