#include<cstdio>
int heap[1000005];
inline void check(register int fath,register int cnt){
int bro=fath*2,j;
if(bro>cnt) return ;
if(bro+1>cnt){
if(heap[fath]>heap[bro]){
int t=heap[bro];
heap[bro]=heap[fath];
heap[fath]=t;
}
}
if(heap[fath]<=heap[bro]&&heap[fath]<=heap[bro+1]){
return ;
}
if(heap[bro]<heap[bro+1]){
j=bro;
}else{
j=bro+1;
}
int o=heap[j];
heap[j]=heap[fath];
heap[fath]=o;
check(j,cnt);
}
int main(){
int n,p=1;
scanf("%d",&n);
for(register int i=1;i<=n;++i){
int a,b;
scanf("%d",&a);
if(a==1){
scanf("%d",&b);
heap[p]=b;
++p;
}else if(a==2){
for(register int j=p/2;j>=1;--j){
check(j,p);
}
printf("%d\n",heap[1]);
}else if(a==3){
heap[1]=0x7ffffff;
}else{
continue;
}
}
return 0;
}