import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] arr = new int[n]; for(int i = 0;i < n;i++){ arr[i] = in.nextInt(); } quicksort(arr,0,n-1); int flag = in.nextInt(); if(flag == 0){ for(int i = 0;i< n;i++){ System.out.print(arr[i]+" "); } } else if(flag == 1){ for(int i = n - 1;i >= 0;i--){ System.out.print(arr[i]+" "); } }

}
public static void quicksort(int[] arr,int l,int r){
    if(l >= r) return ;
    int idx = help(arr,l,r);
    quicksort(arr,l,idx-1);
    quicksort(arr,idx +1,r);
}
public static int help(int[] arr,int l,int r){
    int k = arr[r];
    int low = l;
    int high = r - 1;
    while(low <= high){
        if(arr[low] <= k){
            low ++;
        }else if(arr[high] > k){
            high --;
        }else{
            int cur = arr[low];
            arr[low] = arr[high];
            arr[high] = cur;
        }
    }
    int temp = arr[low];
    arr[low] = arr[r];
    arr[r] = temp;
    return low;
    
}

}