#include<bits/stdc++.h>
using namespace std;
int a[10005]={},cnt=1;
int x;
void add(int now){
int fa=(now-1)/2;
if(a[fa]>a[now]){
swap(a[fa],a[now]);
add(fa);
}
}
void sdx(int cur){
if(2*cur+1>=cnt)
return ;
if(2*cur+2>=cnt)
{
if(a[2*cur+1]<a[cur])
swap(a[2*cur+1],a[cur]);
}
int l=2*cur+1,r=l+1;
if(a[l]>a[r])
swap(a[l],a[r]);
if(a[l]<a[cur])
{
swap(a[l],a[cur]);
sdx(cur);
}
}
void del(){
sdx(cnt--);
}
void init(){
int op;
cin>>op;
if(op==1){
cin>>x;
a[cnt]=x;
add(cnt++);
}
if(op==2){
cout<<a[1]<<endl;
}
if(op==3){
del();
}
}
int main(){
int t;
cin>>t;
while(t--){
init();
}
return 0;
}