#include <stdio.h>
#define N 500000

void max(int);
void build(void);
void printout(void);
int count, i;
int A[N];

int main() {
  int i;

  scanf("%d", &count);
  for( i=0 ; i< count ; i++) scanf("%d", &A[i]);
  build( );
  printout( );
  return 0;
}

void maz( int j ){
  int largest,small;
  if( 2*j+1 <= count && A[2*j+1] > A[j] ) largest = 2*j+1;
  else largest = j;
  if( 2*j+2 <= count && A[2*j+2] > A[largest] ) largest = 2*j+2;
  if( largest!=j ){
    small = A[largest];
    A[largest] = A[j];
    A[j] = small;
    max( largest );
  }
}

void build() {
  int j;
  for( j=count/2-1 ; j>=0 ; j--) max(j);
}

void printout(){
  for( i=0 ; i<count ; i++ ) printf(" %d",A[i]);
  print("\n");
}