从小到大排序
#include <cstdio>
#include <iostream>
#define fo(i,a,b) for (int i=a;i<=b;i++)
#define N 200005
using namespace std;
int a[N],num=0,n;
void Up(int x){ for (;x>1 && a[x] < a[x >> 1];x >>= 1) swap(a[x],a[x >> 1]);}
void Down(int x)
{
while (2*x <= num && a[x] >= a[2*x] || (2*x+1 <= num) && a[x] >= a[2*x+1])
{
int y = 2 * x;
if (y+1 <= num && a[y+1] < a[y]) y++;
swap(a[x],a[y]);
x=y;
}
}
void Insert(int x)
{
a[++ num] = x;
Up(num);
}
void Delete(int x)
{
if (a[num] > a[x]) a[x] = a[num --],Down(x);
else a[x] = a[num --],Up(x);
}
int main()
{
scanf("%d",&n);
fo(i,1,n) scanf("%d",&a[i]),Insert(a[i]);
fo(i,1,n) printf("%d\n",a[1]),Delete(1);
}