#include <fstream>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
int heap[200010];
int pozitie[200010];
int intrare[200010];
int v[200010];
int n, dim, nrIntrat;
void urcare(int c) {
int p = c / 2;
while (p != 0 && heap[c] < heap[p]) {
swap(heap[c], heap[p]);
swap(intrare[c], intrare[p]);
pozitie[intrare[c]] = c;
pozitie[intrare[p]] = p;
c = p;
p = p / 2;
}
}
void coborare(int p) {
int c = 2 * p;
while (c <= dim) {
if (c + 1 <= dim && heap[c + 1] < heap[c])
c = c + 1;
if (heap[p] > heap[c]) {
swap(heap[p], heap[c]);
swap(intrare[p], intrare[c]);
pozitie[intrare[p]] = p;
pozitie[intrare[c]] = c;
p = c;
c = 2 * p;
} else
break;
}
}
void inserare(int x) {
nrIntrat++;
v[nrIntrat] = x;
dim++;
heap[dim] = x;
intrare[dim] = nrIntrat;
pozitie[nrIntrat] = dim;
urcare(dim);
}
void stergere(int ordine) {
int poz = pozitie[ordine];
heap[poz] = heap[dim];
intrare[poz] = intrare[dim];
pozitie[intrare[poz]] = poz;
dim--;
if (poz <= dim) {
urcare(poz);
coborare(poz);
}
}
int main() {
fin >> n;
int cod, x;
for (int i = 1; i <= n; i++) {
fin >> cod;
if (cod == 1) {
fin >> x;
inserare(x);
} else if (cod == 2) {
fin >> x;
stergere(x);
} else {
fout << heap[1] << "\n";
}
}
return 0;
}