• + 0 comments
    if __name__ == '__main__':
        N = int(input())
    
        
        def action(com_list, arr):
            if com_list[0] == 'print':
                print(arr)
            elif com_list[0] == 'pop' and len(arr) > 0:
                arr.pop()
            elif com_list[0] == 'reverse' and len(arr) > 0:
                arr.reverse()
            elif com_list[0] == 'insert':
                i, e = int(com_list[1]), int(com_list[2])
                arr.insert(i, e)
            elif com_list[0] == 'sort':
                arr.sort()
            elif com_list[0] == 'remove':
                try:
                    arr.remove(int(com_list[1]))
                except ValueError:
                    pass
            elif com_list[0] == 'append':
                e = int(com_list[1])
                arr.append(e)
                    
        my_list = []
        
        for i in range(N):
            command = input().split()
            action(command, my_list)