#include #define nmax 200001 int N, l, nr, a[nmax], h[nmax], p[nmax]; using namespace std; void push(int x){ int aux; while(x/2 && a[h[x/2]]>a[h[x]]){ aux=h[x]; h[x]=h[x/2]; h[x/2]=aux; p[h[x]]=x; p[h[x/2]]=x/2; x/=2; }} void pop(int x) { int aux, y(0); while(x!=y) { y=x; if(y*2<=l && a[h[x]]>a[h[y*2]]) x=y*2; if(y*2+1<=l && a[h[x]]>a[h[y*2+1]]) x=y*2+1; aux=h[x]; h[x]=h[y]; h[y]=aux; p[h[x]]=x; p[h[y]]=y; } } int main() {ios_base::sync_with_stdio(0); int ist,x,pz = 0; cin >> N; for(int i(0); i> ist; if(ist==1) { cin >> x; l++; nr++; a[nr]=x; h[l]=nr; p[nr]=l; push(l); pz++;} if(ist==2) { pz--; x = pz;a[x]=-1; push(p[x]); p[h[1]]=0; h[1]=h[l--]; p[h[1]]=1; if(l>1) pop(1); } if(ist==3) cout << a[h[1]]<< "\n"; } return 0; }