#include
using namespace std;
class node
{
public:
node *prev;
int data;
node *next;
node(int d)
{
prev=NULL;
data=d;
next=NULL;
}
};
node *head=NULL;
void Display(node *p)
{
while(p!=NULL)
{
cout<data<<" ";
p=p->next;
}
cout<<endl;
}
void Create(int n)
{
int ele;
cin>>ele;
head=new node(ele);
node *last=head;
for(int i=0;i<n-1;i++)
{
cin>>ele;
node *t=new node(ele);
t->prev=last;
last->next=t;
last=t;
}
}
void InsertionSort(int n)
{
node *p=head;
node *q=head->next;
for(int i=1;i<n;i++)
{
int x=q->data;
while(p->data>x && p!=NULL)
{
p->next->data=p->data;
p=p->prev;
}
if(q->prev!=head)
{
p=head;
}
else
p=q->prev;
p->data=x;
q=q->next;
p=q->prev;
}
}
int main()
{
int n;
cin>>n;
Create(n);
InsertionSort(n);
Display(head);
}