#include<stdio.h>
#define MAX 250
 
int heapsize;
int A[MAX];
int p(int heap){
    return heap/2;
}
int l(int heap){
    return heap*2;
}
int r(int heap){
    return (heap*2+1);
}
 
main(){

    int i,left,right;
    scanf("%d",&heapsize);
     
    for(i = 1;i <= heapsize;i++){
        scanf("%d",&A[i]);
    }
    buildMaxHeap();
    for(i = 1;i <= heapsize;i++)
    printf("%d ",A[i]);
    return 0;
}
 
int maxHeapify(i){
    int largest;
    int left = l(i);
    int right = r(i);
    if(left <= heapsize && A[i]< A[left]){
        largest = left;
    }else{
        largest = i;
    }
    if(right <= heapsize && A[right] > A[largest]){
        largest = right;
    }
    if(largest != i){
        int tmp;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
    maxHeapify(largest);
    }
}
int buildMaxHeap(){
    int i;
    for(i = (heapsize/2); i >= 1;i--){
        maxHeapify(i);
    }
    
}