#include<stdio.h>
#define N 250

int H,T[N];
void BuildMaxHeap();
void MaxHeapify(int );

int main(){

  int i,n;

  scanf("%d",&n);
  H=n;
  for(i=1;i<=n;i++)scanf("%d",&T[i]);

  BuildMaxHeap();

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

void MaxHeapify( int i){
  int l,r,largest,tmp;

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

  if(l<=H && T[i]<T[l])largest=l;
  else largest=i;

  if(r<=H && T[largest]<T[r])largest=r;

  if(largest!=i){
    tmp=T[i];
    T[i]=T[largest];
    T[largest]=tmp;
    MaxHeapify(largest);
  }
  
  
}

void BuildMaxHeap(){
  int i;
  for(i=H/2;i>=1;i--)
    MaxHeapify(i);

  
}