#include<stdio.h>                                                                
 
 int H;
 maxHeapify(int* A,int i){
     int l = A[i*2];
     int r = A[i*2+1];
     int m;
     if( l ≤ H and A[l] > A[i]){
         int largest = l;
     }
     else{
         int largest = i;
     }
     if( r ≤ H and A[r] > A[largest]){
         int largest = r;
     }
     if(largest != i){
         m = A[i];
         A[i] = A[largest];
         A[largest] = m;
         maxHeapify(A, largest);
     }
 }
 
 buildMaxHeap(int* A){
     int i;
     for(i = H/2 ; i >= 1 ; i--){
         maxHeapify(A,i);
     }
 }
 
 int main(){
     int i;
     scanf("%d",&H);
     int tree[H+1];
     for(i = 1 ; i <= H ; i++){
        scanf("%d",&tree[i]);
     }
     buildMaxHeap(H);
     return 0;
 }      

