#include
using namespace std;
int a[1000];
struct Node
{
int data;
Node *next;
};
int main()
{
int x=0,j=0;
while(scanf("%d",&x))
{
if(x==0) break;
a[++j]=x;
}
sort(a+1,a+1+j);
for(int i=1;i<=j;i++)
{
printf("%d ",a[i]);
}
printf("\n");
Node *head,*s,*p,*q;
s=new Node;
s->data=a[j];
head=s;
for(int i=1;i<=j-1;i++)
{
p=s;
s=new Node;
s->data=a[j-i];
p->next=s;
}
s->next=NULL;
p=head;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
return 0;
}