import sys
while True:
    try:
        n = int(input())
        L = list(map(int, input().split()))
        p = input()
        if p == '0':
            print(" ".join(map(str, sorted(L))))
        else:
            print(" ".join(map(str, sorted(L, reverse=True))))
    except:
#         print(sys.exc_info())
        break