#include<stdio.h>
#include<stdlib.h>
struct heap{
int *data;
int maxlenth,lenth;
};
struct heap*Creat(int MaxLenth){
struct heap*p;
p=(struct heap*)malloc(sizeof(struct heap));
p->maxlenth=MaxLenth;
p->lenth=0;
p->data=(int *)malloc(MaxLenth*sizeof(int) );
p->data[0]=100000;
return p;
}
void paixu(struct heap*maxheap){
int i=(maxheap->lenth)/2;
int maxchild,father,child,temp,end;
for(;i>=1;i--){
temp=maxheap->data[i];
end=maxchild=father=i;
child=father*2;
while(child<=maxheap->lenth){
if(child+1<=maxheap->lenth)
maxchild=maxheap->data[child]>maxheap->data[child+1]?child:child+1;
else
maxchild=child;
if(maxheap->data[maxchild]>temp){
maxheap->data[father]=maxheap->data[maxchild];
end=maxchild;
}
else
break;
father=child;
child*=2;
}
maxheap->data[end]=temp;
}
}
void print(struct heap*maxheap,int n){
printf("%d",maxheap->data[n]);
for(n/=2;n>=1;n/=2)
printf(" %d",maxheap->data[n]);
}
void print2(struct heap*maxheap){
int i=1;
printf("%d",maxheap->data[i]);
for(++i;i<=maxheap->lenth;i++)
printf(" %d",maxheap->data[i]);
}
int main(){
int N,i;
struct heap *maxheap;
scanf("%d",&N);
maxheap=Creat(N+1);
for(i=1;i<=N;i++){
scanf("%d",&maxheap->data[++maxheap->lenth]);
}
paixu(maxheap);
print2(maxheap);
return 0;
}