#include <stdio.h>
#include <stdlib.h>

#define HEAP_SIZE 500000
int heap[HEAP_SIZE];
void insert(int val, int heap[], int counter);
void print_structure(int heap[], int start_index ,int s);

int main(){
	int i;
	int h;
	int val = 0; /* insert data */

	scanf("%d", &h);
	for (i = 0; i < h; i++) {
		/* random integer */
		scanf("%d", &val);
		insert(val, heap, i);
	}

	print_structure(heap, 1,h);

	return 1;
}

/* max-heap property */
void insert(int val, int heap[], int counter)
{
	int i = counter + 1;
	while ((i != 1) && (heap[i / 2] < val)) {
		heap[i] = heap[i / 2];
		i = i / 2;
	}
	heap[i] = val;
}

void print_structure(int heap[], int start_index, int h)
{
	int i;
	for (i = start_index; i <= h; i++) {
		printf(" %d", heap[i]);
		/* left node */
		if (i * 2 < h) {
			//printf("\tchild L [%d]: %d\n", i * 2, heap[i * 2]);
		}
		/* right node */
		if (i * 2 + 1 < h) {
			//printf("\tchild R [%d]: %d\n", i * 2 + 1, heap[i * 2 + 1]);
		}
	}
	printf("\n");
}
