#include <stdio.h>

int h,aa[600000];

void mh(int i){
  int l,r,big,t;

  l = i*2;
  r = i*2 + 1;

  if(l<=h && aa[l]>aa[i])big = l;
  else big = i;
  if(r<=h && aa[r] > aa[big])big = r;

  if(big!=i){
    t=aa[i];
    aa[i]=aa[big];
    aa[big]=t;
    mh(big);
  }
}

void bmh(void){
  int i;
  for(i=h/2;1<=i;i--){
    mh(i);
  }
}

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

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

  bmh();

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

  return 0;
}

