#include<cstdio>
using namespace std;
const int MAXN=1000005;
int heap[MAXN],n;
void change(int a,int b) {
int t=heap[a];
heap[a]=heap[b];
heap[b]=t;
}
void siftup(int now) {
while(now!=1) {
if(heap[now]<heap[now/2])
change(now,now/2);
else
return;
now/=2;
}
}
void siftdown(int now) {
while(now*2<=n) {
int t=now;
if(heap[t]<heap[now*2])
t=now*2;
if(now*2+1<=n) {
if(heap[t]<heap[now*2]+1)
t=now*2+1;
}
if(t==now)
return;
change(t,now);
now=t;
}
}
void deletemin() {
heap[1]=heap[n];
n--;
siftdown(1);
}
int main() {
int num,op;
scanf("%d",&num);
for(int i=1;i<=num;i++) {
scanf("%d",&op);
if(op==1) {
int x;
scanf("%d",&x);
heap[++n]=x;
siftup(n);
}
else
if(op==2)
printf("%d\n",heap[1]);
else
deletemin();
}
return 0;
}