#include <stdio.h>

int n;

void maxHeapify(int node[],int i){
  int l =2*i;
  int r = 2*i+1;
  int largest;
  int temp;

  if(l <= n && node[l] > node[i]){
    largest =l;
  }
  else{
    largest = i;
  }
  if(r <= n && node[r] > node[largest]){
    largest = r; 
  }
  if(largest != i){
    temp = node[i];
    node[i] = node[largest];
    node[largest] = temp;
    maxHeapify(node,largest);
  }
}

void buildMaxHeap(int node[]){
  int i;
  for(i=n/2;i>0;i--){
    maxHeapify(node,i);
  }
}

int main(){
  int i,node[250];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&node[i]);
  }

  buildMaxHeap(node);

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

  return 0;
}
   