import java.util.*;
public class Main {
        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();
                if(flag==0){
                    //升序
                    Arrays.sort(arr,new Comparator<Integer>(){
                        public int compare(Integer o1,Integer o2){
                            return o1-o2;
                        }
                    });
                }else if(flag ==1){
                    //降序
                    Arrays.sort(arr,new Comparator<Integer>(){
                        public int compare(Integer o1,Integer o2){
                            return o2-o1;
                        }
                    });
                }
                for(Integer m : arr){
                    System.out.print(m+" ");
                }
                System.out.println();
            }
        }
}