#include<fstream>
#include<vector>
#include<cstring>
using namespace std;
ifstream cin("heapuri.in");
ofstream cout("heapuri.out");
vector<int>v(1, 0);
vector<int>ord;
bool empty()
{
return v.size() == 1;
}
void up(int pos)
{
while(pos > 1 && v[pos] < v[pos / 2])
{
swap(v[pos], v[pos / 2]);
pos /= 2;
}
}
void down(int pos)
{
while(2 * pos < v.size())
{
int min_fiu = 2 * pos;
if(2 * pos + 1 < v.size() && v[2 * pos + 1] < v[min_fiu])
{
min_fiu = 2 * pos + 1;
}
if(v[min_fiu] >= v[pos])
{
break;
}
swap(v[pos], v[min_fiu]);
pos = min_fiu;
}
}
int cautareBinara(int x, int st, int dr)
{
while(true)
{
int med = (st + dr) / 2;
if(v[med] == x)
{
return med;
}
else if(v[med] > x)
{
dr = med - 1;
}
else
{
st = med + 1;
}
}
}
int main()
{
int t; cin >> t;
for(int i = 0; i < t; i++)
{
char cerinta; cin >> cerinta;
if(cerinta == '1')
{
int x; cin >> x;
v.push_back(x);
up(v.size() - 1);
ord.push_back(x);
}
else if(cerinta == '2')
{
int poz; cin >> poz;
int ind = cautareBinara(ord[poz - 1], 1, v.size());
swap(v[ind], v[v.size() - 1]);
v.pop_back();
up(ind);
down(ind);
}
else
{
if(!empty())
{
cout << v[1] << "\n";
}
}
}
return false;
}