#include<bits/stdc++.h>
#include <functional>
using namespace std;
int main(){
vector<int> a;
int n, m;
cin >> n;
for(int i = 0; i < n; i ++){
cin >> m;
a.push_back(m);
}
int k;
cin >> k;
if(k == 0){//up
sort(a.begin(), a.end());
}else if (k == 1){//down
sort(a.begin(), a.end(), greater<int>());
}
vector<int>::iterator it = a.begin();
while(it != a.end()){
cout << *it << " ";
it ++;
}
}