while True:
try:
n = int(input())
nums = map(int, input().split())
mode = int(input())
# 降序
if mode:
for i in sorted(nums, reverse=True):
print(i, end=' ')
# 生序
else:
for i in sorted(nums):
print(i, end=' ')
print()
except:
break