#include<iostream>
using namespace std;
typedef int datatype;
struct NODE {
datatype data;
struct NODE* next;
};
typedef struct NODE* node;
node create(node list,datatype x)
{
node t, newnode = new NODE;
newnode->data = x;
newnode->next = NULL;
if (list == NULL) list = newnode;
else
{
t = list;
while (t->next != NULL)
{
t = t->next;
}
t->next = newnode;
}
return list;
}
node Insert(node list,datatype x)
{
node newnode = new NODE;
node p, q;
p = list;
q = list;
newnode->data = x;
newnode->next = NULL;
if (p == NULL)
{
p = newnode;
return p;
}
else if (p->data >= x)
{
newnode->next = p;
return newnode;
}
else
{
while (p->next!=NULL&&x>=p->data)
{
q = p;
p = p->next;
}
if (p->next == NULL) p->next = newnode;
else
{
newnode->next = q->next;
q->next = newnode;
}
return list;
}
}
int main()
{
int n, i, x, y;
node t=NULL;
cin >> n;
for (i = 1; i <= n; i++)
{
cin >> x;
t = create(t, x);
}
cin >> y;
t = Insert(t, y);
while (t)
{
cout << t->data << " ";
t = t->next;
}
return 0;
}