#include <set>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
int main() {
multiset <int> my_set;
vector <int> my_vector;
int n;
fin >> n;
int x;
for (int i = 0; i < n; i++)
{
fin >> x;
if (x == 3) {
multiset <int>::iterator it = my_set.begin();
fout << *it << "\n";
} else if (x == 2) {
fin >> x;
if (my_set.begin() != my_set.end()) my_set.erase(my_vector[x-1]);
} else {
fin >> x;
my_vector.push_back(x);
my_set.insert(x);
}
}
return 0;
}