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

int main(){
    int n;
    while(cin >> n){
        vector<int> v;
        int m;
        for(int i=0; i<n; i++){
            cin >> m;
            v.push_back(m);
        }
        int k;
        cin >> k;
        if(k==0){
            sort(v.begin(),v.end());
        }
        else if(k==1){
            sort(v.begin(),v.end(),greater<int>());
        }
        copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));
        cout << endl;
    }
}