#include <iostream>
using namespace std;
void sortt (int *,int,int,int,int);
void mer (int*,int,int,int);
void coutt (int*a,int s)
{
for (int i=0;i<s;i++)
cout << a[i] << " ";
cout<<endl;
}
int main()
{
int siza;
while (cin>>siza)
{
int a[siza];
for (int i=0;i<siza;i++)
cin>>a[i];
mer(a,0,siza-1,siza);
cout<<endl;
for (int i=0;i<siza;i++)
cout <<a[i]<<" ";
}
}
void mer (int *a,int L,int R,int s)
{
int m;
if (L<R)
{
m=(L+R)/2;
mer (a,L,m,s);
mer (a,m+1,R,s);
sortt (a,L,m,R,s);
}
}
void sortt (int *a,int L,int m, int R,int s)
{
int l,r,i,tem[s];
l=L;
r=m+1;
i=L;
while((l<=m)&&(r<=R))
{
if (a[l]<a[r])
{
tem[i]=a[l];
i++,l++;
}
else
{
tem[i]=a[r];
i++,r++;
}
}
while (l<=m)
{
tem[i]=a[l];
i++,l++;
}
while (r<=R)
{
tem[i]=a[r];
i++,r++;
}
for (i=L;i<=R;i++)
a[i]=tem[i];
}