import java.io.*;
import java.util.*;

public class Main {
   public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int num = Integer.parseInt(bf.readLine());
        int [] arr = new int[num];
        String [] str = bf.readLine().split(" ");
        for(int i = 0; i< num; i++){
            arr[i] = Integer.parseInt(str[i]);
        }
        int sortType = Integer.parseInt(bf.readLine());
        sort(arr);
        StringBuilder sb = new StringBuilder();
        if(sortType==1){
            for(int i = arr.length-1;i>=0;i--){
                 sb.append(arr[i]).append(" ");
            }
        }else{
            for(int item: arr){
                sb.append(item).append(" ");
            }
        }
       System.out.println(sb.toString());
    }
    private static void sort(int[] arr) {
        int[] temp = new int[arr.length];
        sort(arr, 0, arr.length-1, temp);
    }      
    private static void sort(int[] arr, int left, int right, int[] temp) {
        if (left < right){
            int mid = (left + right) / 2;
            sort(arr, left, mid,temp);
            sort(arr, mid+1, right,temp);
            merge(arr, left, mid, right, temp);
        }
    }

    private static void merge(int[] arr, int left, int mid, int right, int[]temp) {
        int lIndex = left;
        int rIndex = mid +1;
        int tempIndex = left;
        while (lIndex <= mid && rIndex <=right){
            if (arr[lIndex] <= arr[rIndex]){
                temp[tempIndex++] = arr[lIndex++];
            }else {
                temp[tempIndex++] = arr[rIndex++];
            }
        }
        while (lIndex <= mid){
            temp[tempIndex++] = arr[lIndex++];
        }
        while (rIndex <= right){
            temp[tempIndex++] = arr[rIndex++];
        }
        while (left <= right){
            arr[left] = temp[left++];
        }

    }
}