#include <stdio.h>
int main() {
int a[10];
int temp;
for (int i = 0; i < 5; i++) {
scanf("%d", &a[i]);
}
for(int i = 0; i < 4; i++) {
for(int j=0;j<4-i;j++)
{
if (a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for (int i = 0; i < 5; i++) {
printf("%d ", a[i]);}
for (int i = 5; i < 10; i++) {
scanf("%d", &a[i]);
}
for(int i = 5; i < 9; i++) {
for(int q=0;q<4-i;q++)
{
if (a[q]<a[q+1])
{
temp=a[q+1];
a[q+1]=a[q];
a[q]=temp;
}
}
}
for (int i = 4; i < 10; i++) {
printf("%d ", a[i]);}
return 0;
}