#include<stdio.h>
int x[2000000],n;
void max(int a){
  int left,right,m,temp;
  left=2*a;
  right=2*a+1;
  if(left<=n && x[left]>x[a]){
    m=left;
  }
  else{
    m=a;
  }
  if(right<=n&&x[right]>x[m])m=right;
  if(m!=a){
    temp=x[a];
    x[a]=x[m];
    x[m]=temp;
    max(m);
  }
} 
int main(){
  int i;
  scanf("%d",&n);
     
  for(i=1;i<=n;++i){
    scanf("%d",&x[i]);
  }
  for(i=n/2;i>=1;--i){
    max(i);
  }  
  for(i=1;i<=n;++i){
    printf(" %d",x[i]);
  }
  printf("\n");
     
  return 0;
}


