#include <stdio.h>
struct Heap{
	int value;
}MaxHeap[500000];
int heapCount=0;

void insert(int value){
	if(heapCount==500000){
		printf("Heap Penuh");
		return;
	}
	heapCount++;
	MaxHeap[heapCount].value=value;
	
	int currJmlhData=heapCount;
	while(currJmlhData!=1 && MaxHeap[currJmlhData/2].value<MaxHeap[currJmlhData].value){
		Heap temp=MaxHeap[currJmlhData];
		MaxHeap[currJmlhData]=MaxHeap[currJmlhData/2];
		MaxHeap[currJmlhData/2]=temp;

		currJmlhData/=2;
	}
}

void heapDown(int parentIdx){
	Heap currValue=MaxHeap[parentIdx];
	int currIdx=parentIdx;
	if((parentIdx*2)<=heapCount && currValue.value<MaxHeap[parentIdx*2].value){
		currValue=MaxHeap[parentIdx*2];
		currIdx=parentIdx*2;
	}
	if((parentIdx*2+1)<=heapCount && currValue.value<MaxHeap[parentIdx*2+1].value){
		currValue=MaxHeap[parentIdx*2+1];
		currIdx=parentIdx*2+1;
	}
	if(currIdx==parentIdx)return;
	Heap temp=MaxHeap[parentIdx];
	MaxHeap[parentIdx]=MaxHeap[currIdx];
	MaxHeap[currIdx]=temp;

	heapDown(currIdx);
}

int deleteMax(){
	if(heapCount==0)
		return 1<<30;
	if(heapCount==1){
		heapCount--;
		return MaxHeap[heapCount].value;
	}
	
	Heap deletedValue=MaxHeap[1];
	MaxHeap[1]=MaxHeap[heapCount];
	heapCount--;

	heapDown(1);
	return deletedValue.value;
}

void print(){
	for(int i=1;i<=heapCount;i++)
		printf("%d ",MaxHeap[i].value);
}

int main(){
	int h;
	int value;
	scanf("%d",&h);
	for(int i=0;i<h;i++){
		scanf("%d",&value);
		insert(value);
	}
	print();
	return 0;
}
