#include <stdio.h>
#define MAX 250
int A[MAX];
void maxHeapify(int,int);
  int main(){
    int i,n;
    for(i = 0;i<MAX;i++){
      A[i]=0;
    }
    scanf("%d",&n);
    for(i=1;i<=n;i++){
      scanf("%d",&A[i]);
    }

    for(i = n/2 ;i>=1;i--){
         maxHeapify(i,n);
    }
    for(i = 1 ;i<=n;i++){
      if(i ==n){
	printf(" %d\n",A[i]);
      }
      else  printf(" %d",A[i]);
   
    }
    return 0;
  }
  void maxHeapify(int i,int n){
  int l,r,leargest=0,tmp=0;
  l = 2*i;
  r  = (2*i)+1;
  if(l<=n && A[l]>A[i]){
    leargest =l;
  }
  else leargest = i;
  if(r<=n && A[r] >A[leargest])
    {
      leargest = r;
    }
  if(leargest !=i){
    tmp =  A[i];
    A[i] = A[leargest];
    A[leargest] = tmp;
  maxHeapify(leargest,n);
  }
}

