def m(h,a,i)
  l,r,x=i*2,i*2+1,i
  l<=h&&a[x]<a[l]&&x=l
  r<=h&&a[x]<a[r]&&x=r
  x!=i&&(a[i],a[x]=a[x],a[i])&&m(h,a,x)
end
h=gets.to_i
a=[nil]+gets.split.map(&:to_i)
(h/2).downto(1){|i|m(h,a,i)}
puts a*' '
