#include<stdio.h>

int p;
int q[500010];
void find(int i){
  int d=i;
	if(2*i  <=p&&q[2*i  ]>q[d])d=2*i;
	if(2*i+1<=p&&q[2*i+1]>q[d])d=2*i+1;
	if(d!=i){
		int t=q[i];
		q[i]=q[d];
		q[d]=t;
		find(d);
	}
}
int main(){
	scanf("%d",&p);
	for(int i=1;i<=p;i++)scanf("%d",q+i);
	for(int i=p;i>0;i--)find(i);
	for(int i=1;i<=p;i++)printf(" %d",q[i]);
	puts("");
}

