#include <iostream>
using namespace std;
#include <list>

bool sortU(int a,int b){
    if(a>b){
        return false;
    }
    return true;
}

bool sortD(int a,int b){
    if(a<b){
        return false;
    }
    return true;
}


int main() {
    int num,a,type;
    cin >> num;
    list<int> lst;
    for(int i = 0; i < num ;i++){
        cin >> a;
        lst.push_back(a);
    }
    cin >> type;
    if(type == 0){
        lst.sort(sortU);
    }
    else{
        lst.sort(sortD);
    }

    for(auto x : lst){
        cout << x <<" ";
    }
}

list和自定义排序函数的应用