#include<stdio.h>
void Swap(int *a,int *b)
{
int t;
t=*a;
*a=*b;
*b=t;
}
void MaxHeap(int arr[],int n,int i)
{
int largest=i;
int left=2*i+1,right=2*i+2;
if(left<n&&arr[left]>arr[largest])
largest=left;
if(right<n&&arr[right]>arr[largest])
largest=right;
if(largest!=i)
{
Swap(&arr[i],&arr[largest]);
MaxHeap(arr,n,largest);
}
}
void HeapSort(int arr[],int n)
{
int i;
for(i=n/2-1;i>=0;i--)
{
MaxHeap(arr,n,i);
}
for(i=n-1;i>0;i--)
{
Swap(&arr[0],&arr[i]);
MaxHeap(arr,i,0);
}
}
int main()
{
int n,i,arr[100];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
HeapSort(arr,n);
for(i=0;i<n;i++)
{
printf("%d,",arr[i]);
}
return 0;
}