#include<stdio.h>
#define T 500001
int hep[T];
int o;
void hen(int *i,int *m){
  int te;
  te =*i;
  *i=*m;
  *m=te;
}
void hepfy(int i){
  int max;
  int tem;
  if(i*2<= o &&hep[i*2]>hep[i]){
    max=i*2;
  }
  else max=i;
  
  if(i*2+1<=o &&hep[i*2+1]>hep[max]){
    max=i*2+1;
  }

  if(max !=i){
    tem= hep[i];
     
    hep[i]=hep[max];
    hep[max]= tem;
    hepfy(max); 
  }
}
void hep2(){
  int i;
  for(i=o/2;i>=1;i--){
    hepfy(i);
  }
}

int main(){
  int i;
  scanf("%d",&o);
  for(i=1;i<=o;i++){
    scanf("%d",&hep[i]);
  }

  hep2();
 
  for(i=1;i<=o;i++){
    printf(" %d",hep[i]);
  }
  printf("\n");
  return 0;
}

