#include <stdio.h>
#define H 251

void swap(int a, int b){
  int temp;
  temp = a;
  a = b;
  b = temp;
}

void Max_Heapify( int *A, int i){

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

  if(l <= H && A[l] > A[i]){
    largest = l;
  }else{
    largest = i;
  }

  if(r <= H && A[i] > A[largest]){
    largest = r;
  }
  if(largest != i){
    swap(A[i] , A[largest]);
    Max_Heapify(A, largest);
  }
}


int main(){

  int A[H], heap, i;

  A[0] = 0;

  scanf("%d", &heap);
  for(i = 1; i <= heap; i++){
    scanf("%d", &A[i]);
  }
  //  for(i = heap/2; i > 0; i--){
   Max_Heapify( A, i);
   //  }

  for(i = 1; i <= heap; i++){
    printf(" %d", A[i]);
  }
  printf("\n");

  return 0;
}