#include <stdio.h>

#define M 500001

int hp,tree[M];

void Max_retu(int x){
  int R,L,change,s;
  L=2*x;
  R=2*x+1;
  
  if(L<=hp && tree[x]<tree[L]){
    s=L;
  }
  else s=x;
  if(R<=hp && tree[s]<tree[R]){
    s=R;
  }
  if(s!=x){
    change=tree[x];
    tree[x]=tree[s];
    tree[s]=change;
    Max_retu(s);
  }
}


int main(){
  int i;

  scanf("%d",&hp);

  for(i=1;i<=hp;i++){
    scanf("%d",&tree[i]);
  }

  for(i=hp/2;i>=1;i--){
    Max_retu(i);
  }

  for(i=1;i<=hp;i++){
    printf(" %d",tree[i]);
  }
  printf("\n");

  return 0;
}
      

