#include<bits/stdc++.h>
using namespace std;
std::priority_queue<int,vector<int>,greater<int> >a;
int main()
{
int b,c[100001],d[500001];
cin>>b;
for(int i=1;i<=b;i++)
{
cin>>c[i];
if(c[i]==1)
{
cin>>d[i];
}
}
for(int i=1;i<=b;i++)
{
if(c[i]==1)
{
a.push(d[i]);
}
if(c[i]==2)
{
std::cout<<a.top()<<endl;
}
if(c[i]==3)
{
a.pop();
}
}
return 0;
}