#include <stdio.h>
 
  
void maxH(int *node, int i, int g){
  int large, s;
     
  if(i*2 <= g && node[i*2] > node[i]) large = i*2;
  else large = i;
  if(i*2+1 <= g && node[i*2+1] > node[large])large = i*2+1;
  
  if(large != i){
    s = node[i];
    node[i] = node[large];
    node[large] = s;
    maxH(node, large, g);
  }
}
  
main(){
  int i, g;
  int node[500001];
  
  scanf("%d", &g);
  
  for(i=1;i<=g;i++) scanf("%d", &node[i]);
  
  for(i =g/2;i>0;i--) maxH(node,i,g);
  
  
  for(i=1;i<=g;i++) printf(" %d",node[i]);
  
  printf("\n");
  return 0; 
}