#include <fstream>
using namespace std;
const int MAXCOMENZI = 200005;
ifstream in("heapuri.in");
ofstream out("heapuri.out");
int heap[MAXCOMENZI];
int nr_heap = 0;
int pozitie[MAXCOMENZI];
int nod[MAXCOMENZI];
int nr_noduri = 0;
void interschimbare(int a, int b)
{
int aux = heap[a];
heap[a] = heap[b];
heap[b] = aux;
pozitie[heap[a]] = a;
pozitie[heap[b]] = b;
}
void urcare(int pos)
{
if (pos == 1 || nod[heap[pos / 2]] < nod[heap[pos]])
return;
interschimbare(pos, pos / 2);
urcare(pos / 2);
}
void inserare(int nr)
{
++nr_noduri;
++nr_heap;
heap[nr_heap] = nr_noduri;
nod[nr_noduri] = nr;
pozitie[nr_noduri] = nr_heap;
urcare(nr_heap);
}
void coborare(int pos)
{
int pos2 = pos;
if (pos2 * 2 <= nr_heap && nod[heap[pos2 * 2]] < nod[heap[pos]])
pos = pos2 * 2;
if (pos2 * 2 + 1 <= nr_heap && nod[heap[pos2 * 2 + 1]] < nod[heap[pos]])
pos = pos2 * 2 + 1;
if (pos2 != pos)
{
interschimbare(pos,pos2);
coborare(pos);
}
}
void stergere(int pos)
{
nod[pos] = -1;
urcare(pozitie[pos]);
pozitie[heap[1]] = 0;
heap[1] = heap[nr_heap];
heap[nr_heap] = 0;
--nr_heap;
pozitie[heap[1]] = 1;
if (nr_heap > 1)
coborare(1);
}
int main()
{
int nr_comenzi;
in >> nr_comenzi;
int tip_comanda, x;
for (int i = 1;i <= nr_comenzi;++i)
{
in >> tip_comanda;
if (tip_comanda == 1)
{
in >> x;
inserare(x);
}
if (tip_comanda == 2)
{
in >> x;
stergere(x);
}
if (tip_comanda == 3)
out << nod[heap[1]] << '\n';
/*for (int i = 1;i <= nr_heap;++i)
printf("%d ",nod[heap[i]]);
printf("\n");*/
}
return 0;
}