#include <fstream>
#include <vector>
using namespace std;
vector <pair<long long,pair<long long, long long >>> heap;
long long i;
long long introdus = 1;
void urca(long long poz)
{
while (poz)
{
if(heap[(poz-1)/2].first>heap[poz].first) {
swap(heap[(poz - 1) / 2].first, heap[poz].first);
swap(heap[(poz - 1) / 2].second.first, heap[poz].second.first);
poz = (poz-1)/2;
}
else
break;
}
}
void coboara(long long poz) {
if (poz * 2 + 1 >= heap.size())
return;
long long fiu_st = heap[poz * 2 + 1].first;
if ((poz * 2 + 2 == heap.size()) || fiu_st < heap[poz * 2 + 2].first) {
if (fiu_st < heap[poz].first) {
swap(heap[poz].first, heap[poz * 2 + 1].first);
swap(heap[poz].second.first, heap[poz * 2 + 1].second.first);
coboara(poz * 2 + 1);
return;
} else {
return;
}
} else {
if (heap[poz * 2 + 2].first < heap[poz].first) {
swap(heap[poz].first, heap[poz * 2 + 2].first);
swap(heap[poz].second.first, heap[poz * 2 + 2].second.first);
coboara(poz * 2 + 2);
return;
} else {
return;
}
}
}
int main()
{
ifstream f("heapuri.in");
ofstream g("heapuri.out");
long long n,op,nr,poz;
f>>n;
long long k = 0;
for(i = 1;i<=n;i++) {
f >> op;
switch (op) {
case 1: {
f >> nr;
heap.push_back({nr, {introdus, k}});
urca(k);
introdus++;
k++;
break;
}
case 2: {
f >> poz;
long long j;
k--;
for (j = 0; j < heap.size() - 1; j++)
if (heap[j].second.first == poz)
break;
heap[j].first = heap[heap.size() - 1].first;
heap[j].second.first = heap[heap.size() - 1].second.first;
heap.pop_back();
urca(heap[j].second.second);
coboara(heap[j].second.second);
break;
}
case 3: {
g << heap[0].first << '\n';
break;
}
}
}
f.close();
g.close();
return 0;
}