#include<stdio.h>
int array[10000000];
int number;




int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}









void max (int i){
  int l,r,largest;

  l=left(i);
  r=right(i);

  if(l<=number && array[l]>array[i]){largest=l;}

  else{largest=i;}

  if(r<=number && array[r]>array[largest]){largest=r;}

  int tmp;
  if(largest !=i){
    tmp=array[i];
    array[i]=array[largest];
    array[largest]=tmp;

    max(largest);
  }


}


int main(){

  
  scanf("%d",&number);


  
  int i;
  for(i=1;i<=number;i++){
    scanf("%d",&array[i]);
    }

  for(i=number/2;i>=1;i--){max(i);}


   for(i=1;i<=number;i++){
     {printf(" %d",array[i]);}
   
    }

   printf("\n");

  



  void max (int i);
  

  return 0;
}


