#include<stdio.h>
#define M 2000000

int H;

void MH(int *A,int i){
  int work;
  int l,r,b;
  l = 2 * i;
  r = 2 * i + 1;

  if(l <= H && A[l] > A[i]) b = l;
  else b = i;
  if(r <= H && A[r] > A[b]) b = r;

  if(b != i){
    work = A[i];
    A[i] = A[b];
    A[b] = work;    
    MH(A,b);
  }
}

int main(){
  int A[M+1],i;
  scanf("%d",&H);

  for(i = 1; i <= H; i++) scanf("%d",&A[i]);
  for(i = H/2;i >= 1; i--) MH(A,i);
  for(i = 1; i <= H; i++) printf(" %d",A[i]);
  printf("\n");

  return 0;
}
  
  

