#include <stdio.h>
#define MAX 250


int A[MAX];
int heap_size;


void maxheapify(int heap[],int j){
  int largest,leftH,rightH;
    int tmp;
 

    leftH = Left(j);


    rightH = Right(j);

  if(leftH <= heap_size && heap[leftH] >heap[j]){
    largest=leftH;
  }

  else {
    largest=j;
  }

  if(rightH <= heap_size && heap[rightH] > heap[largest]){
   
 largest=rightH;

  }
  if(largest != j){

    tmp=heap[largest];

    heap[largest]=heap[j];


    heap[j]=tmp;
    maxheapify(heap,largest);
  }
}
 




void Buildmaxheap(int heap[]){

  int j,i;

  i=heap_size/2;
  for(j=i;j >= 1;j--){
    maxheapify(heap,j);
  }


}




int Left(int i){

  return 2*i;
}

int Right(int i){

  return 2*i+1;
}

main(){

  int i;


  scanf("%d",&heap_size);

  for(i=1;i <= heap_size;i++){

    scanf("%d",&A[i]);

  }

  Buildmaxheap(A);

  for(i=1;i <= heap_size;i++){

    
    printf(" %d",A[i]);

  }  
      printf("\n");
  
  return 0;
}