#include <stdio.h>
#define MAX 250

int parent(int );
int left(int );
int right(int );
void buildMaxHeap(int []);
void maxHeapify(int [],int);

int n;

int main(void){
  
  int i;
  int Tree[MAX];
  
  scanf("%d",&n);
  
  for(i = 1; i <= n;i++)
    scanf("%d",&Tree[i]);
  
  
  buildMaxHeap(Tree);
  
  for(i = 1;i <= n;i++)
    printf(" %d",Tree[i]);
  
  printf("\n");
  
  return 0;
}

int parent(int i){
  return i / 2;
}

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

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

void buildMaxHeap(int Tree[]){
  int i;

  for(i = n/2;i >= 1;i--)
    maxHeapify(Tree, i);
}

void maxHeapify(int Tree[], int i){
  int l = left(i);
  int r = right(i);
  int largest;
  int tmp;

  if(l <= n && Tree[l] > Tree[i])
    largest = l;

  else
    largest = i;

  if(r <= n && Tree[r] > Tree[largest])
    largest = r;

  if(largest != i){
    tmp = Tree[largest];
    Tree[largest] = Tree[i];
    Tree[i] = tmp;
    maxHeapify(Tree, largest);
  }
}