#include<stdio.h>
#define MAX 250

int heapsize;
int HEAP[MAX];
int p(int heap){
	return heap/2;
}
int l(int heap){
	return heap*2;
}
int r(int heap){
	return (heap*2+1);
}

main(){
	int i,left,right;
	scanf("%d",&heapsize);
	
	for(i = 1;i <= heapsize;i++){
		scanf("%d",&HEAP[i]);
	}
	buildMaxHeap(HEAP);
	for(i = 0;i < heapsize;i++)
	printf("%d ",HEAP[i]);
	return 0;
}

void maxHeapify(A,i){
	int largest;
	int left = l(i);
	int right = r(i);
	if(left <= heapsize && A[i]< A[left]){
		largest = left;
	}else{
		largest = i;
	}
	if(right <= heapsize && A[right] > A[largest]){
		largest = r;
	}
	if(largest != i){
		int tmp;
		tmp = A[i];
		A[i] = A[largest];
		A[largest] = tmp;
	maxHeapify(A,largest);
	}
}
void buildMaxHeap(A){
	int i;
	for(i = (heapsize/2); i > 1;i--){
		maxHeap(A,i);
	}