#include <stdio.h>
#include <stdlib.h>

int comparea(const void* a, const void* b) {
    int* intA = (int*)a;
    int* intB = (int*)b;
    return *intA - *intB;
}

int compared(const void* a, const void* b) {
    int* intA = (int*)a;
    int* intB = (int*)b;
    return *intB - *intA;
}

int main() {
    int n, o;
    int val[1000];
    while (scanf("%d", &n) != EOF) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &val[i]);
        }
        scanf("%d", &o);
        if (o == 0) {
            qsort(val, n, sizeof(int), comparea);
        } else if (o == 1) {
            qsort(val, n, sizeof(int), compared);
        }
        for(int i = 0; i < n - 1; i++) {
            printf("%d ", val[i]);
        }
        printf("%d\n", val[n - 1]);
    }
    return 0;
}