Program Heap_Sort_Mpq_2007_1_31;
const Maxn=1000000;
type data=array[1..Maxn] of longint;
var
a:data;
i,n,Tmp:longint;
procedure heap(n,i:longint);
var
x,j:longint;
begin
x:=a[i];
j:=2*i;
while j<=n do
begin
if (j<n) and (a[j]<a[j+1]) then j:=j+1;
if x<a[j] then
begin
a[i]:=a[j];
i:=j;
j:=j*2;
end else break;
end;
a[i]:=x;
end;
begin
assign(input,'sort.in'); reset(input);
assign(output,'sort.out'); rewrite(output);
readln(n);
for i:=1 to n do readln(a[i]);
for i:=n div 2 downto 1 do
heap(n,i);
for i:=n downto 2 do
begin
Tmp:=a[1];
a[1]:=a[i];
a[i]:=Tmp;
heap(i-1,1);
end;
for i:=1 to n do writeln(a[i]);
close(input); close(output);
end.