while True:
    
    try:
        m = int(input())
        num_list = list(map(int, input().split()))
        n = int(input())
        if n == 0:
            print(' '.join(map(str, sorted(num_list))))
        elif n == 1:
            print(' '.join(map(str, sorted(num_list,reverse=True))))
        
        
    except:
        break