#include<iostream>
using namespace std;
const int N = 1e4 + 5, M = 1e4 + 5;
int a[N];
int n;
void show()
{
for(int i = 1; i <= n; i++)
cout << a[i] << ' ';
}
void adjust(int num, int parent)
{
int child = parent * 2;
if(child + 1 <= num && a[child] < a[child + 1])
child ++;
if(a[child] > a[parent])
{
swap(a[child], a[parent]);
if(child < num / 2)
adjust(num, child);
}
}
void heapSort()
{
for(int i = n; i > 1; i--)
{
for(int j = i / 2; j >= 1; j--)
adjust(i, j);
swap(a[1], a[i]);
}
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
heapSort();
show();
return 0;
}