while True: try: a = int(input()) b = list(map(int, input().split())) c = input() if c == "0": print(*sorted(b)) # *用于解开list elif c == "1": print(*sorted(b, reverse=True)) except: break