*a=p
def m a,i
r=1+l=2*j=i
x,y=a[l,2]
x&&x>a[i]&&j=l
y&&y>a[j]&&j=r
j!=i&&(a[i],a[j]=a[j],a[i]
m a,j)
end
(c,k=$_.split
c[?i]? (i=a.size
a.push k.to_i
(a[i],a[k]=a[k],a[i]
i=k)while i>1&&a[k=i/2]<a[i]): c[?x]? (p a[1]
a[1]=a.pop
m a,1):p)while gets