#include <bits/stdc++.h>
using namespace std;

#define name "SORT"
const int MAXN = 2e5+5;
int n, a[MAXN];

void setIO(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(name".inp", "r")){
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }
}

int main(){
	setIO(); // Nhập xuất file
	cin >> n;
	for (int i = 0; i<n; i++) cin >> a[i];
	
	// Sắp xếp tăng dần
	sort(a, a+n);
	for (int i = 0; i<n; i++) cout << a[i] << " ";
	cout << "\n";
	
	// Sắp xếp giảm dần
	sort(a, a+n, greater<int>());
	for (int i = 0; i<n; i++) cout << a[i] << " ";
}