#include <bits/stdc++.h>
#define NMAX 200005
using namespace std;
ifstream fin ("heapuri.in");
ofstream fout ("heapuri.out");
int H[NMAX],P[NMAX],N;
void percolate(int k){
int key = H[k],poz = P[k];
while(k > 1 && H[k] > H[(k >> 1)]){
K[k] = H[(k >> 1)];
P[k] = P[(k >> 1)];
k = k >> 1;
}
H[k] = key;
P[k] = poz;
}
int main()
{
ios :: sync_with_stdio(false);
int n,t,x,k = 0;
fin >> n;
while(n--){
fin >> t;
if(t == 1){
fin >> x;
H[N++] = x;
P[N] = N;
percolate(N);
}
if(t == 2){
fin >> x;
H[p[x]] = H[N];
P[N] = P[x];
}
if(t == 3)
fout << H[1] << "\n";
}
cout << "Hello world!" << endl;
return 0;
}