#include
int h[101];
int n;
void swap(int x, int y)
{
int t;
t = h[x];
h[x] = h[y];
h[y] = t;
return;
}
void siftdown(int i)
{
int t, flag=0;
// i*2 <= n 表示çå«ä¹æ¯ièç¹è³å°æå·¦å¿å
// i*2+1 <= n 表示ièç¹æä¸¤ä¸ªå¿å
while(i*2 <= n && flag == 0)
{
if(h[i] > h[i*2])
t = i*2;
else
t = i;
if(i*2+1 <= n)
{
if(h[t] > h[i*2 + 1])
t = i*2 + 1;
}
if(t != i)
{
swap(t,i);
// ç»§ç»å䏿£ç´¢ï¼ç´å°è¶
è¿å å
ç´ ä½ç½®
i = t;
}
else
// 鲿¢å·²ç»åå°åéçä½ç½®
flag=1;
}
return;
}
void siftup(int i)
{
int flag=0;
if(i == 1) return;
while(i != 1 && flag==0)
{
if(h[i]=1; i--)
{
siftdown(i);
}
return;
}
/*int deletemax()
{
int t;
t = h[1];
h[1] = h[n];
n--;
siftdown(1);
return t;
}*/
void heapsort()
{
while(n>1)
{
swap(1,n);
n--;
siftdown(1);
}
return;
}
int main()
{
int i, num;
scanf("%d", &num);
for(i=1; i<=num; i++)
scanf("%d", &h[i]);
n = num;
create();
heapsort();
for(i=1; i<=num; i++)
printf("%d ", h[i]);
return 0;
}