#include<stdio.h>
int cmp(const void *a, const void *b){
if(*(int*)a > *(int*)b)return 1;
else if(*(int*)a < *(int*)b)return -1;
return 0;
}
int main(){
int n;
scanf("%d", &n);
int arr[n];
for(int i = 0; i < n; ++i)
scanf("%d", &arr[i]);
qsort(arr, n, sizeof(int), cmp);
for(int i = 0; i < n; ++i)
printf("%d ", arr[i]);
printf("\n");
printf("%d ", arr[n-1]);
for(int i = n-2; i >= 0; --i){
if(arr[i] == arr[i+1])
continue;
else
printf("%d ", arr[i]);
}
return 0;
}