#include <iostream>
using namespace std;
#define MAXN 200000
#define INSERT 1
#define DELETE 2
#define QUERY 3
struct Node{
int val, cron;
};
Node heap[MAXN];
int heap_size;
int cronToHeap[MAXN];
inline int parent(int i){
return (i - 1) / 2;
}
inline int leftChild(int i){
return i * 2 + 1;
}
inline int rightChild(int i){
return i * 2 + 2;
}
void upHeap(int i){
while(i && heap[i].val < heap[parent(i)].val){
swap(heap[i], heap[parent(i)]);
cronToHeap[heap[i].cron] = i;
cronToHeap[heap[parent(i)].cron] = parent(i);
i = parent(i);
}
}
void downHeap(int i){
int left, right, smallest;
smallest = i;
do{
i = smallest;
left = leftChild(i);
right = rightChild(i);
if(left < heap_size && heap[smallest].val > heap[left].val){
smallest = left;
}
if(right < heap_size && heap[smallest].val > heap[right].val){
smallest = right;
}
if(smallest != i){
swap(heap[i], heap[smallest]);
cronToHeap[heap[i].cron] = i;
cronToHeap[heap[parent(i)].cron] = parent(i);
}
}while(smallest != i);
}
void insert(int val, int cron){
heap[heap_size] = {val, cron};
cronToHeap[cron] = heap_size;
heap_size++;
upHeap(heap_size - 1);
}
int getMin(){
return heap[0].val;
}
void delete_from_heap(int cron){
int i;
i = cronToHeap[cron];
heap[i] = heap[heap_size - 1];
cronToHeap[heap[heap_size - 1].cron] = i;
heap_size--;
upHeap(i);
downHeap(i);
}
int main(){
FILE *fin, *fout;
fin = fopen("heapuri.in", "r");
fout = fopen("heapuri.out", "w");
int n, op, x, i, cronIndex;
fscanf(fin, "%d", &n);
cronIndex = 0;
for(i = 0; i < n; i++){
fscanf(fin, "%d", &op);
if(op != QUERY){
fscanf(fin, "%d", &x);
if(op == INSERT){
insert(x, cronIndex++);
}
else{
delete_from_heap(x - 1);
}
}
else{
fprintf(fout, "%d\n", getMin());
}
}
fclose(fin);
fclose(fout);
return 0;
}