#include
using namespace std;
int n,len,op;
long long heap[1000005],x;
void put(int x){
heap[++len]=x;
int p=len;
while(p!=1&&heap[p]len)return ;
if(p*2+1>len){
if(heap[p]>heap[p*2]){
swap(heap[p],heap[p*2]);
p*=2;
}
else return ;
}
else{
if(heap[p*2]>heap[p*2+1])q=p*2+1;
else q=p*2;
if(heap[p]>heap[q]){
swap(heap[p],heap[q]);
p=q;
}
else return ;
}
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&op);
if(op==1){
scanf("%lld",&x);
put(x);
}
else if(op==2)
printf("%lldn",heap[1]);
else
pop();
}
return 0;
}