#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool compare(int a, int b)
{
    return a > b;
}
int main()
{
    int n;
    cin >> n;
    vector<int> arr;
    int num;
    for (int i = 0; i < n; i++) {
        cin >> num;
        arr.push_back(num);
    }
    int order;
    cin >> order;
    if (order == 0) {
        sort(arr.begin(), arr.end());
    } else {
        sort(arr.begin(), arr.end(), compare);
    }
    for (int i = 0; i < n; i++) {
        cout << arr[i] << " ";
    }
    cout << endl;
    return 0;
}