n = int(input())
l = [int(i) for i in input().split()]
if input() == "0":
    l.sort()
else:
    l.sort(reverse=True)
print(" ".join(map(str,l)))