# -*-coding:utf-8-*-
import string
while True:
try:
input_n = input()
input_b = input().split(" ")
input_m = int(input())
list_b=[]
for i in input_b:
i = int(i)
list_b.append(i)
if input_m == 0:
list_b.sort()
elif input_m == 1:
list_b.sort(reverse=-1)
else:
break
for j in list_b:
print(j,end=" ")
except:
break