#include<stdio.h>
#include<stdlib.h>
#define tree_t long int*
#define first 0
int count; //??????heap???????????????

typedef struct node
{
    tree_t d;
    int number;
    int max_num;

} heap;

void clear_heap(heap* answer)
{
    int i;
    free(answer->d);
    answer->number = -1;
    answer->max_num = 0;
}

void swap(long int *n1,long int *n2)
{
    long int setp;
    count++;    // ????????????????¨?????¬????
    setp = *n1;
    *n1 = *n2;
    *n2 = setp;

}


void creat_heap(heap* in,int max_)//?°±????????????
{
    in->d = (tree_t)malloc(max_*sizeof(int));
    in->max_num = max_;
    in->number = -1;
}

void heap_down(heap* answer,int root,int botten)  //heap_down ??????
{
    int lchild = root*2+1;
    int rchild = root*2+2;
    int max_child;

    if(lchild < botten)
    {
        if(answer->d[lchild]>=answer->d[rchild])
        {
            max_child = lchild;
        }
        else
        {
            max_child = rchild;
        }

        if(answer->d[root] < answer->d[max_child])
        {
            swap(&(answer->d[root]),(&answer->d[max_child]));
        }
        heap_down(answer,lchild,botten);
        if(rchild < botten)
            heap_down(answer,rchild,botten);
    }
    return;
}

void heap_up(heap* answer,int botten)   //heap_up??????(??¶?????¨?????°
{
    int root = 0;
    int parent;
    if(botten > root)
    {
        parent = (botten-1)/2;

        if(answer->d[parent] < answer->d[botten])
        {
            //printf("%d %d\n",answer->d[parent] , answer->d[botten]);
            swap(&(answer->d[parent]), &(answer->d[botten]));
            //printf("%d %d\n\n",answer->d[parent] , answer->d[botten]);
            heap_up(answer,parent);
        }
    }
    return;

}

void out_h(heap* answer)
{
    int i;
    for(i=0; i <= answer->number; i++)
    {
        printf(" %ld",answer->d[i]);
    }
    printf("\n");

}

int main()
{

    int max_;

    while(scanf("%d",&max_)!=EOF)
    {

        heap answer;
        creat_heap(&answer,max_);
        long int input;
        int i;
        for(i=0; i<max_; i++)
        {
            scanf("%ld",&input);
            answer.d[i] = input;
            answer.number++;
        }
        count = 1;
        while(count)
        {
            //swap(&(answer.d[first]),&(answer.d[answer.number]));
            count = 0;
            heap_down(&answer,first,max_);
        }

        out_h(&answer);
        clear_heap(&answer);


    }


    return 0;
}