while 1:
    try:
        input()
        lst = [int(i) for i in input().split()]
        r = int(input())
        if r == 0:
            lst.sort()
        else:
            lst.sort(reverse=True)
        lst = [str(i) for i in lst]
        print(' '.join(lst))
    except:
        break