#include <cstdio> |
#include <cctype> |
#include <iostream> |
using namespace std; |
int n,num,ins,x,heapp[1000001]; |
inline int read() |
{ |
int x=0; |
bool w= false ; |
char ch=0; |
while (! isdigit (ch)) |
{ |
w|=ch== '-' ; |
ch= getchar (); |
} |
while ( isdigit (ch)) |
{ |
x=(x<<1)+(x<<3)+(ch^48); |
ch= getchar (); |
} |
return w?-x:x; |
} |
inline void delete_it() |
{ |
heapp[1]=heapp[num]; |
int now=1; |
num--; |
while ((now<<1)<=num) |
{ |
int nexxt=now<<1; |
if (nexxt+1<=num&&heapp[nexxt+1]<heapp[nexxt]) nexxt++; |
if (heapp[nexxt]<heapp[now]) swap(heapp[nexxt],heapp[now]); |
else break ; |
now=nexxt; |
} |
} |
inline void sift_up( int x) |
{ |
int p=x; |
while (p) |
{ |
int fa=p>>1; |
if (heapp[fa]>heapp[p]) swap(heapp[fa],heapp[p]); |
else break ; |
p=fa; |
} |
} |
inline void build( int x) |
{ |
heapp[++num]=x; |
sift_up(num); |
} |
int main() |
{ |
ios::sync_with_stdio( false ); |
n=read(); |
for ( register int i=1;i<=n;i++) |
{ |
ins=read(); |
if (ins==1) |
{ |
x=read(); |
build(x); |
} |
else if (ins==2) cout<<heapp[1]<<endl; |
else delete_it(); |
} |
return 0; |
} |