#include<stdio.h>

#define H 250

int A[H],size;

int left(i){
  return i*2;
}

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

void maxHeapify(int B[],int i){
  int l = left(i);
  int r = right(i);
  int tmp,largest;
  if(l<=H && B[l]>B[i]) largest = l;
  else largest = i;
  if(r<=H && B[r]>B[largest]) largest = r;

  if(largest != i){
      tmp = B[i];
    B[i] = B[largest];
    B[largest] = tmp;
    maxHeapify(B, largest);
      }
}
void  buildMaxHeap(int B[]){
  for(int i=size/2;i>=1;i--){
    maxHeapify(B, i);
      }
}


int main(void){
  int i;
  scanf("%d",&size);
  
  for(i=1;i<=size;i++) scanf("%d",&A[i]);

  buildMaxHeap(A);

  for(i=1;i<=size;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}