#include<cmath>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define LL long long
#define MOD 10000000
priority_queue <int,vector<int>,less<int> > p;
priority_queue <int,vector<int>,greater<int> > q;
LL read()
{
LL x=0,w=1;
char ch=0;
while(ch<'0'||ch>'9')
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return w*x;
}
int n,t,f;
int main()
{
n=read();
while(n--)
{
f=read();
if(f==1)
{
t=read();
q.push(t);
}
if(f==2)
{
cout<<q.top()<<endl;
}
if(f==3)
{
q.pop();
}
}
return 0;
}