{$apptype console}
const
 fin='heapsort.in';
 fout='heapsort.out';
var
  A:array[1..100000] of longint;
  N,i:longint;
procedure Heapify(k:longint);
var
  i,j,max:longint;
begin
  if ((2*k)<=n)and(A[k]<A[2*k]) then max:=2*k else max:=k;
  if ((2*k+1)<=n)and(A[max]<A[2*k+1]) then max:=2*k+1;
  if k<>max then
    begin
      j:=a[k];
      a[k]:=a[max];
      a[max]:=j;
      Heapify(max);
    end;
end;
  
begin
 assign(Input,fin); reset(input);
 assign(Output,fout); rewrite(output);
 readln(n);
 for i:=1 to n do A[i]:=i;

 for i:=n downto 1 do
   begin
     Heapify(i);
   end;
 for i:=1 to n do
   write(a[i],' ');
 close(input); close(output);
end.