using namespace std;
#include <vector>
#include <algorithm>
class Heap
{
private:
vector <int> h;
int size;
void percolate(int node)
{
while(node && h[node/2]>=h[node])
{
swap(h[node],h[node/2]);
node/=2;
}
}
void sift(int node)
{
int f1,f2;
int son=node;
do
{
node=son;
f1=2*node,f2=2*node+1;
if(f1 < size && h[f1]<h[son] ) son=f1;
if(f2 < size && h[f2]<h[son] ) son=f2;
swap(h[node],h[son]);
}while(node!=son);
}
public:
void insert(int x)
{
h.push_back(x);
percolate(h.size()-1);
size=h.size();
}
int top()
{
return h[0];
}
void pop()
{
h[0]=h[h.size()-1];
h.pop_back();
size--;
sift(0);
}
}H;
#include <fstream>
ifstream f("algsort.in");
ofstream g("algsort.out");
int main()
{
int N;
f>>N;
int i,x;
for(i=1;i<=N;i++)
{
f>>x;
H.insert(x);
}
for(i=1;i<=N;i++)
{
g<<H.top()<<' ';
H.pop();
}
}