#include<stdio.h>

#define MAX 2000000

int E,T[MAX+1];

void heap(int i){
  int lo,ro,bigest,temp;
  
  lo=2*i;
  ro=2*i+1;
  
  if(lo <= E && T[lo]>T[i]){
    bigest=lo;
  }
  
  else bigest=i;
  
  if(ro<=E && T[ro]>T[bigest]){
    bigest=ro;
  }
  
  if(bigest != i){
    temp=T[i];
    T[i]=T[bigest];
    T[bigest]=temp;
    heap(bigest);
  }
}





int main(){
  int i;
  
  scanf("%d",&E);


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

  for(i=E/2;i>=1;i--){
    heap(i);
  }

  for(i=1;i<=E;i++){
    printf(" %d",T[i]);
  }

  printf("\n");

  return 0;
}




