#include<stdio.h>
using namespace std;
const int N = 200005;
int h[N], p, val[N], poz[N], ct;
void schimba (int p1, int p2)
{
int aux = h[p1];
h[p1] = h[p2];
h[p2] = aux;
poz[h[p1]] = p1;
poz[h[p2]] = p2;
}
void urca (int p2)
{
while (p2 > 1)
{
if (val[h[p2]] < val[h[p2 / 2]])
schimba (p2, p2 / 2);
p2 >>= 1;
}
}
void coboara (int p2)
{
int fs = 2 * p2, fd = 2 * p2 + 1, bun = p2;
if (fs <= p && val[h[fs]] < val[h[bun]])
bun = fs;
if (fd <= p && val[h[fd]] < val[h[bun]])
bun = fd;
if (bun != p2)
{
schimba (bun, p2);
coboara (bun);
}
}
int main ()
{
FILE *in, *out;
in = fopen ("heapuri.in" ,"r");
out = fopen ("heapuri.out", "w");
int n;
fscanf (in, "%d", &n);
int cerinta, i, x, p2;
for (i = 1; i <= n; i++)
{
fscanf (in, "%d", &cerinta);
if (cerinta == 1)
{
fscanf (in, "%d", &x);
ct++;
p++;
h[p] = ct;
poz[ct] = p;
val[ct] = x;
urca (p);
}
if (cerinta == 2)
{
fscanf (in, "%d", &x);
p2 = poz[x];
schimba (poz[x], p--);
coboara (p2);
urca(p2);
}
if (cerinta == 3)
fprintf (out, "%d\n", val[h[1]]);
}
return 0;
}