import java.util.Arrays;
import java.util.Scanner;

/**
 * HJ101 输入整型数组和排序标识,对其元素按照升序或降序进行排序
 */
public class HJ101 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            Integer[] arr = new Integer[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            int flag = sc.nextInt();
            //升序
            Arrays.sort(arr, (o1, o2) -> {
                if (flag == 0) {
                    return o1 - o2;
                } else {
                    return o2 - o1;
                }
            });
            for (Integer m : arr) {
                System.out.print(m + " ");
            }
            System.out.println();
        }
        sc.close();
    }

}