n = int(input())
arr = list(map(int, input().split(" ")))
flag = int(input())

if flag == 0:
    arr.sort()
else:
    arr.sort(reverse=True)

for i in range(n):
    print(arr[i], end=" ")